我的應用程序有時崩潰,我知道在哪裏,但我不知道爲什麼。請觀看此代碼:Android Nullpointer異常按鈕
private Button btFacebook
@Override
public final void onCreate(Bundle savedInstanceState)
{
....
btFacebook = (Button) findViewById(R.id.bt_fb_zaloguj);
btFacebook.setText(getResources().getString(R.string.act_logowanie_bt_facebook).toUpperCase()); //line crash
....
}
爲什麼btFacebook有時爲空?
編輯:
> java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.gosell.ghmaster/pl.gosell.ghmaster.activity.ActSplash}: java.lang.NullPointerException
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
android.app.ActivityThread.access$900(ActivityThread.java:161)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:157)
android.app.ActivityThread.main(ActivityThread.java:5356)8at java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
pl.gosell.ghmaster.activity.ActSplash.onActivityData(ActSplash.java:184)
com.android.lifter.activity.ActivityBase.onCreate(ActivityBase.java:99)
android.app.Activity.performCreate(Activity.java:5426)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
19... 11 more
你的logcat在哪裏?發表它。 – 2014-10-03 07:17:50
如果您的應用程序在加載時崩潰,則可能因爲上述原因,如果在加載後崩潰,則意味着該按鈕正在執行的任何功能都會導致崩潰。只有回答這個問題的方法是,如果你發佈錯誤的logcat,否則人們會盲目地給出答案。 – NightwareSystems 2014-10-03 09:15:39