0

In my app there is one activity I have where I call onDestroy and inside it I have the following:

@Override
public void onDestroy()
{
    productAdapter.imageLoader.stopThread();

    lvProducts.setAdapter(null);
    super.onDestroy();
}

productAdapter is my ListView adapter and I am using the fedorvlasov lazy load functionality.

The issue is, when I leave the app for a LONG time and come back, I try to access this activity from the main activity and I get the following:

03-22 09:15:17.684: ERROR/AndroidRuntime(28442): FATAL EXCEPTION: main
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): java.lang.RuntimeException: Unable to destroy activity {com.MyApp/com.MyApp.Products}: java.lang.NullPointerException
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3081)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3146)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread.access$2100(ActivityThread.java:132)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1071)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.os.Looper.loop(Looper.java:150)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread.main(ActivityThread.java:4263)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at java.lang.reflect.Method.invokeNative(Native Method)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at java.lang.reflect.Method.invoke(Method.java:507)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at dalvik.system.NativeStart.main(Native Method)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442): Caused by: java.lang.NullPointerException
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at com.MyApp.Productss.onDestroy(DailyDeals.java:678)
03-22 09:15:17.684: ERROR/AndroidRuntime(28442):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3063)

The thing is, I dont know how to reproduce this because it only happens if I leave the app for a long time and come back. Its almost like there is an Android timeout that says after this many hours, cause app to start over.

Jesse
  • 2,674
  • 6
  • 30
  • 47

1 Answers1

1

The system will kill your application whenever it needs the resources to use for something else. This is why when you come back after a long time it is no longer running.

why do you have this line?

lvProducts.setAdapter(null);

I think that is what is giving you a null pointer. It isn't liking that you are trying to set it with a null adapter. Try removing this line

Also just to be sure, which line is 678?

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • The fedor lazylist example has you do the following in onDestroy: adapter.imageLoader.stopThread(); list.setAdapter(null); – Jesse Mar 22 '12 at 13:51
  • But why is it even calling onDestroy when I ENTER the activity. – Jesse Mar 22 '12 at 13:52
  • 678 is productAdapter.imageLoader.stopThread(); I could just check for null productAdapter and null imageLoader first, but how can I force the app to reproduce this? – Jesse Mar 22 '12 at 13:55
  • That I wouldn't know. Can you link the example you are working from? – FoamyGuy Mar 22 '12 at 13:57
  • http://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012 – Jesse Mar 22 '12 at 14:00
  • Ok, I think I am wrong then about passing null in being the problem. Try checking for nulls before you do anything it might also be worth it to add logs to each of your onXXXXX() activity lifecycle methods, so you can get a clear picture of what is being called when. – FoamyGuy Mar 22 '12 at 14:11