我一直在研究我的论文,而且我一直坚持接收短信。我能够将广播接收者的消息正文传递给活动,并在活动中为消息干杯。但是,有多个图像按钮,特定图像按钮将根据消息正文进行更改。 我的代码看起来像:
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
答案 0 :(得分:0)
引起:java.lang.NullPointerException 01-24 18:39:35.341:E / AndroidRuntime(30941):at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)
第63行......