Android“传递结果 ResultInfo 失败”当意图不为空时

发布于 2024-12-15 14:27:32 字数 1922 浏览 2 评论 0原文

我的动态壁纸中有一个自定义图像首选项,允许用户从 SD 卡中选择图像用作背景。我从此处获取了代码,并且没有修改它,所以它几乎完全是除了变量或对象名称之外,其他都相同。

我在我的开发控制台中收到了一些堆栈跟踪:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=file:///mnt/sdcard/com.idunnolol.rageface/rage_fullpanel.png }} to activity {gilleland.software.pixelrain/gilleland.software.pixelrain.PixelRainSettings}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
at android.app.ActivityThread.access$2800(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at gilleland.software.pixelrain.PixelRainSettings.getRealPathFromURI(PixelRainSettings.java:107)
at gilleland.software.pixelrain.PixelRainSettings.onActivityResult(PixelRainSettings.java:90)
at android.app.Activity.dispatchActivityResult(Activity.java:3890)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
... 11 more

我在自己的手机上没有收到此异常。

我已经搜索了一段时间来找出导致 NullPointerException 的原因,但我发现的大多数解决方案都涉及“ResultInfo{who=null, request=1, result=-1, data=null}”。我得到的堆栈跟踪实际上有数据意图......所以我无法弄清楚 NullPointerException 是来自什么。

感谢任何和所有的帮助。我可以提供任何必要的代码来帮助解决这个问题。 谢谢!

I have a custom image preference in my Live Wallpaper that allows a user to choose an image from their SD card to use as a background. I got the code from here and haven't modified it, so it's almost exactly the same except for variable or object names.

I've been getting a few of these stack traces in my dev console:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=file:///mnt/sdcard/com.idunnolol.rageface/rage_fullpanel.png }} to activity {gilleland.software.pixelrain/gilleland.software.pixelrain.PixelRainSettings}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
at android.app.ActivityThread.access$2800(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at gilleland.software.pixelrain.PixelRainSettings.getRealPathFromURI(PixelRainSettings.java:107)
at gilleland.software.pixelrain.PixelRainSettings.onActivityResult(PixelRainSettings.java:90)
at android.app.Activity.dispatchActivityResult(Activity.java:3890)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
... 11 more

I don't get this exception on my own phone.

I've been searching for a while to figure out what's causing the NullPointerException but most of the solutions I have found involve "ResultInfo{who=null, request=1, result=-1, data=null}". The stack traces I'm getting actually have Intents with data...so I can't figure out what the NullPointerException is from.

Any and all help is appreciated. I can provide any necessary code to help solve this.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2024-12-22 14:27:32

requestCode 和 resultCode 是正确的,所以我猜问题是由于以下代码部分中的变量指针之一未正确初始化:

Uri selectedImage = data.getData();   
String RealPath;
SharedPreferences customSharedPreference =        
getSharedPreferences(fingerflashpro.SHARED_PREFS_NAME, Context.MODE_PRIVATE); 
SharedPreferences.Editor editor = customSharedPreference.edit ();
RealPath = getRealPathFromURI (selectedImage);
editor.putString("image_custom", RealPath); 
editor.commit(); 

它可能与 selectedImage 或 RealPath 相关。注释掉大部分代码,逐行调试。

The requestCode and resultCode is correct, so I guess the problem is due to one of the variable pointer is not properly initialized in following section of code:

Uri selectedImage = data.getData();   
String RealPath;
SharedPreferences customSharedPreference =        
getSharedPreferences(fingerflashpro.SHARED_PREFS_NAME, Context.MODE_PRIVATE); 
SharedPreferences.Editor editor = customSharedPreference.edit ();
RealPath = getRealPathFromURI (selectedImage);
editor.putString("image_custom", RealPath); 
editor.commit(); 

It's probably something related to the selectedImage or RealPath. Comment out most of the codes and debug it line by line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文