我一直在写我的论文,但我一直在接收短信。我能够将消息正文从广播接收器传递到活动并在活动中烤消息。但是,有多个图像按钮,并且特定的图像按钮将根据消息正文发生变化。我的代码看起来像:
public String message;
.
.
.
//in my onCreate
.
.
.
Intent intent = getIntent();
message=intent.getStringExtra("messagefrombroadcastreceiver");
//Toast message here
if(message.equals("1")){
//set imagebutton1
}else if(message.equals("2")){
//set imagebutton2
}
.
.
.
.
该应用程序能够发送消息,但是当我添加 if-else-if 部分时它会强制关闭。我真的不知道我做错了什么
LOGCAT 是...
01-24 18:39:35.271: W/dalvikvm(30941): threadid=1: thread exiting with uncaught exception (group=0x400f1560)
01-24 18:39:35.341: E/AndroidRuntime(30941): FATAL EXCEPTION: main
01-24 18:39:35.341: E/AndroidRuntime(30941): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesistrial1/com.example.thesistrial1.Thesis}: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Looper.loop(Looper.java:130)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.main(ActivityThread.java:3735)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
01-24 18:39:35.341: E/AndroidRuntime(30941): at dalvik.system.NativeStart.main(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): Caused by: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-24 18:39:35.341: E/AndroidRuntime(30941): ... 11 more
01-24 18:39:35.341: E/AndroidRuntime(30941): [Blue Error Handler] Make Debugging Report file for main
01-24 18:39:35.341: E/AndroidRuntime(30941): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesistrial1/com.example.thesistrial1.Thesis}: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Looper.loop(Looper.java:130)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.main(ActivityThread.java:3735)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
01-24 18:39:35.341: E/AndroidRuntime(30941): at dalvik.system.NativeStart.main(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): Caused by: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-24 18:39:35.341: E/AndroidRuntime(30941): ... 11 more