I’ve been working on an app that suddenly wont work on my droid x2 test device but works just fine on everything else. I’ve tried turning on and off the phone, deleting the existing copy of the app and reinstalling, and finally I actually went and did a factory reset but for what ever reason when the main activity goes to instantiate the context that I use is coming up null how ever its only doing this on one device and no others.
I went through and checked my manifest flags and I’m pretty sure that’s not it.
When I debugged and stepped through the application I noticed that from oncreate it goes strait to onResume and where I use the context for a method it comes up null but only when I run it on the droid x2. It wont do that on any other device.
The strangest thing is that this never happened before today and I haven’t made any changes to the code in about 3 days. In fact its only been a problem for the past couple of hours.
here’s the logcat when it fails:
02-20 19:30:12.354: E/AndroidRuntime(21483): java.lang.RuntimeException: Unable to resume activity {graffit.main/graffit.main.MyView}: java.lang.NullPointerException
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2208)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2228)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1721)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:968)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.os.Looper.loop(Looper.java:130)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.main(ActivityThread.java:3806)
02-20 19:30:12.354: E/AndroidRuntime(21483): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 19:30:12.354: E/AndroidRuntime(21483): at java.lang.reflect.Method.invoke(Method.java:507)
02-20 19:30:12.354: E/AndroidRuntime(21483): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-20 19:30:12.354: E/AndroidRuntime(21483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-20 19:30:12.354: E/AndroidRuntime(21483): at dalvik.system.NativeStart.main(Native Method)
02-20 19:30:12.354: E/AndroidRuntime(21483): Caused by: java.lang.NullPointerException
02-20 19:30:12.354: E/AndroidRuntime(21483): at graffit.main.MyView.onResume(MyView.java:728)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.Activity.performResume(Activity.java:3912)
02-20 19:30:12.354: E/AndroidRuntime(21483): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2191)
02-20 19:30:12.354: E/AndroidRuntime(21483): ... 12 more
The crash happens when I log in and the MyView activity is supposed to open but the context is null. I know that because I debugged and at this method in my code where I use the context I see its null.
@Override
protected void onResume() {
super.onResume();
try{
System.gc();
myContext.startGpsListener();
//Log.w("curLoc is from"+myContext.curLoc.getProvider(),"thats it");
}catch(Exception e){
e.printStackTrace();
}
if(getIntent().hasExtra("UID")){
curr_uid = getIntent().getStringExtra("UID");
curr_rid = getIntent().getStringExtra("RID");
curr_profimg = getIntent().getStringExtra("imagepath");
curr_usrname = getIntent().getStringExtra("UsrName");
myContext.setUserInfo(curr_uid, curr_usrname);<-------------failure here
}
where are you initializing
myContext? since you are in activity, call startGpsListener(); directly and if possible, call System.gc() as the last statement in method