繁体   English   中英

收到短信后如何更改imagebutton中的图像

[英]how to change image in imagebutton when sms is received

我一直在研究论文,并且一直都在接收短信。 我能够将消息主体从广播接收器传递到活动,并在活动中传递消息。 但是,有多个图像按钮,并且特定的图像按钮将根据消息正文进行更改。 我的代码如下所示:

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

引起原因:java.lang.NullPointerException 01-24 18:39:35.341:E / AndroidRuntime(30941):at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)

第63行...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM