在我的应用程序中,我点击了一个名为Pick Photo的按钮,它加载了图库.当我单击图库中的图像时,应用程序强制关闭,在我的logcat中,我收到以下内容:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,request=1,result=-1,data=Intent { dat=content://media/external/images/media/3369 (has extras) }} to activity {cap.shot/cap.shot.LolcatActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:2655)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2697)
at android.app.ActivityThread.access$2000(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at cap.shot.LolcatView.loadFromUri(LolcatView.java:137)
at cap.shot.LolcatActivity.loadPhoto(LolcatActivity.java:384)
at cap.shot.LolcatActivity.onActivityResult(LolcatActivity.java:299)
at android.app.Activity.dispatchActivityResult(Activity.java:3988)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2651)
我的lolcatactivity.java可以在这里找到:http://pastebin.com/AVL8CswT
我的lolcatview.java可以在这里找到:http://pastebin.com/vD7vCBgY
谢谢!
最佳答案
getDrawable在你的情况下返回null.
您用于setImageURI的uri可能无效,因此您将获得null.
原文链接:https://www.f2er.com/android/430735.html您用于setImageURI的uri可能无效,因此您将获得null.
对drawable执行null检查,如果drawable为null,则需要保释.
编辑:
if(drawable == null)
return;