3

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!

Community
  • 1
  • 1
Gilleland
  • 176
  • 3
  • 7

1 Answers1

1

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.

cnbuff410
  • 206
  • 3
  • 10
  • The only problem with trying to find the cause of this exception is that I don't get this error on my own phone or any device that my friends own. – Gilleland Jan 30 '12 at 04:45
  • I think the problem is due to getRealPathFromURI. it doesn't have consisten behavior across different devices. For example, some pictures taken from camera need not return a URI everytime – cnbuff410 Feb 01 '12 at 01:46
  • That's definitely where the exception is occurring, and only on certain phones, but why throw an exception when there is data being returned? – Gilleland Feb 02 '12 at 03:40
  • What do you mean? NullPointerException is thrown out on line 107 so there must be a pointer pointing to nothing. Just check what's on line 107 – cnbuff410 Feb 02 '12 at 17:16
  • Ah, you're right, I need to change my title. RealPath is returning null ( I'm assuming). But there's no fix for this? All I can do is add a catch but that won't fix the issue of not being able to choose images for some users. – Gilleland Feb 03 '12 at 02:35
  • If getRealPathFromURI is on line 107, all I can suggest is to use another method to read image. Like I said it is not consistent method to invoke on multiple platforms – cnbuff410 Feb 04 '12 at 18:53