android程序运行报错空指针问题

调试程序报错空指针,求广大网友帮忙看看怎么回事
MainActivity.java的部分代码:

public void initView() {

title = (TextView) findViewById(R.id.title);
phonenumber = (TextView) findViewById(R.id.phonenumbertxt);
helpinfotext = (TextView) findViewById(R.id.helpinfotext);

selectCompanyLayout = (LinearLayout) findViewById(R.id.companyname_layout);
companynameTxt = (TextView) findViewById(R.id.companynametxt);
companynameTxt.setText("");//**********这里报空指针错误*********
getNumberLayout = (LinearLayout) findViewById(R.id.number_layout);
order_numTxt = (EditText) findViewById(R.id.order_numtxt);

searchBtn = (Button) findViewById(R.id.searchbtn);
historyBtn = (Button) findViewById(R.id.historybtn);

selectCompanyLayout.setOnClickListener(this);
searchBtn.setOnClickListener(this);
historyBtn.setOnClickListener(this);

progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage("正在为您查询...");//664872754739
progressDialog.setCancelable(true);
progressDialog.setTitle("提示信息");

changeBtnBackground();
if (!Common.hasShortcut(this)) { // 创建快捷方式
Common.addShortcut(this);
}

if (!Common.onlineFlag(MainActivity.this)) {

Toast.makeText(this, "离线使用中,非联网状态不能查询订单信息!", Toast.LENGTH_SHORT)
.show();

}
}


Logcat中的记录:
Process: com.example.viewpager, PID: 14743
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.viewpager/com.checkpackage.checkpackage.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
            at android.app.ActivityThread.access$1000(ActivityThread.java:164)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:159)
            at android.app.ActivityThread.main(ActivityThread.java:5541)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
            at com.checkpackage.checkpackage.MainActivity.initView(MainActivity.java:86)
            at com.checkpackage.checkpackage.MainActivity.onCreate(MainActivity.java:70)
            at android.app.Activity.performCreate(Activity.java:6107)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2458)
????????????at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2577)
????????????at android.app.ActivityThread.access$1000(ActivityThread.java:164)
????????????at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
????????????at android.os.Handler.dispatchMessage(Handler.java:102)
????????????at android.os.Looper.loop(Looper.java:159)
????????????at android.app.ActivityThread.main(ActivityThread.java:5541)
????????????at java.lang.reflect.Method.invoke(Native Method)
????????????at java.lang.reflect.Method.invoke(Method.java:372)
????????????at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
????????????at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值