0

I have two activities Suppose A and B;

activity A has several objects of View [TextView, TabView, ListView etc]:

I fire an Intent using startActivityForResult and go to activity B

then i do my computation as required in activity B and return back to activity A by setRuslt and then finish();

on returning to my onActivityResult i work according to the result sent from activity B;

Everything above works perfectly fine.[During testing]

But when i have deployed my application I am facing crashes [unexpected Nullpointer exception]

-> In some cases ListView inside my onResume method is null;

-> In some cases my tabView is null;

-> In some cases my database object instance is null;

am I missing any important step of the activity lifecycle. It works fine while in testing.

Please Note: I have map Views on both the activities

Please help. Thank you in advance.

HERE's AN STACK TRACE

java.lang.NullPointerException
at in.abmulani.thisway.MainActivity.onKeyDown(MainActivity.java:511)
at android.view.KeyEvent.dispatch(KeyEvent.java:2719)
at android.app.Activity.dispatchKeyEvent(Activity.java:2419)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:190)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:4150)
at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:4112)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3292)
at android.os.Handler.dispatchMessage(Handler.java:99)
Pararth
  • 8,114
  • 4
  • 34
  • 51
AabidMulani
  • 2,325
  • 1
  • 28
  • 47
  • Please show some code of how you navigate between activities – the-ginger-geek Mar 10 '14 at 06:42
  • Log cat is the crash report! and it points to my listView object [NullPointer] and the amount of null pointer that is encountered will force to post my entire code[thatz not possible dude] – AabidMulani Mar 10 '14 at 06:51
  • It never occurs during testing i have 6 devices and works fine in those device. But i dont know from where do they occur after deploying on the playstore – AabidMulani Mar 10 '14 at 06:54
  • @AabidMulani dude..okay! crash report then! should be used to figure out the first crash it reports, atleast that gives you a starting point. if the "amount of null pointer that is encountered..." , is so much then the code doesn't look too good and testing has been considering static cases only. See if you can figure the first NPE and post l-o-c related to that. It may help, to start with – Pararth Mar 10 '14 at 07:03
  • @AabidMulani which is line no.511 in MainActivity.java ? – Pararth Mar 10 '14 at 07:26
  • tabHost.setCurrentTab(0); – AabidMulani Mar 10 '14 at 07:45
  • and i dont know why is it null at that point. [yes, its called immediately after onActivityResult] – AabidMulani Mar 10 '14 at 07:47
  • inspect the value of tabHost and its declaration in activity – Pararth Mar 10 '14 at 08:26

1 Answers1

0

Sometimes the data in the onActivityResult is null.Have you checked it?

And if your activity has a LaunchMode of SingleInstance,the onActivityResult will be invoked by android as soon as you starActivityForResult.Make sure your activity is not a SingleInstance activity.

Last, what you have done in the onResume method?

tianwei
  • 1,859
  • 1
  • 15
  • 24
  • No SingleInstance, i have modified nothing in the manifest for the launchMode – AabidMulani Mar 10 '14 at 06:53
  • Maybe the data object return to your onActivityResult is null,and you should check why the listview got a NullPointerException(data source is updated to a null,or some other errors?) – tianwei Mar 10 '14 at 06:56
  • it fine if the data object returned is null [I am checking for null condition], but the listView object is pointed as Null not my data. why is that? – AabidMulani Mar 10 '14 at 06:58
  • Do i need to use these methods [I am not sure, Never used them]: **onSaveInstanceState** **onRestoreInstanceState** – AabidMulani Mar 10 '14 at 06:59
  • I think your should show some code of your logcat or source. – tianwei Mar 10 '14 at 07:00
  • Updated my question!...This is one of the crash – AabidMulani Mar 10 '14 at 07:06
  • Maybe onSaveInstanceState can really solve your problem.Because you said nothing occurs when you test it.I think this problem maybe occurred in some cheap phones that not have enough memory.when you do a startActivityForResult,your activity is in background,it can be destroy by adnroid because of low memory currently. – tianwei Mar 10 '14 at 07:09
  • Please provide some resource of how to use onSaveInstanceState; and btw Nexus S is one of the device which is facing the crash – AabidMulani Mar 10 '14 at 07:10
  • You should find which data is the reason for the problem,then put it in the savedInstanceState(which is a bundle,can putSerializable) and restore it in onRestoreInstanceState.The most important is:how to find this data object. – tianwei Mar 10 '14 at 07:19