This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
NullPointerException on onSaveInstanceState with AndroidFragments
when I call super.onSaveInstanceState I get a
NullPointerException
at android.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1542)
on some devices, some others work.
public void onSaveInstanceState(Bundle savedInstanceState) {
//...
super.onSaveInstanceState(savedInstanceState);
}
With Android 4.1 on a Nexus Tablet its working, on a Samsung with Android 4.0 not. What is the problem here and how can I solve it? Uncommenting onSaveInstanceState works, but I dont think this is correct and it makes my app behave incorrect somewhere else.
Thanks
Marvin
edit
added stacktrace
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1542)
at android.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1572)
at android.app.Activity.onSaveInstanceState(Activity.java:1164)
at com.MApp.MActivity.onSaveInstanceState(MActivity.java:1111)
at android.app.Activity.performSaveInstanceState(Activity.java:1113)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1188)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3337)
at android.app.ActivityThread.access$700(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4507)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Ok I figured it out now.
This is because my fragment had no
onSaveInstanceState
I had to fill the bundle with dummy values.
It's a bug in android in version 4.0. However, I don't know about other versions.
Related
I just finished integrating Firebase real time data base and Authentication into my Android Studio application. It ran successfully two or three times on my Google Nexus 7 genymotion emulator that has google play services on it. Then I tried launching it again and I started getting the below error:
06-25 16:50:46.994 7699-7699/
com.careersvirtualsolutions.uprate E/AndroidRuntime:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.google.firebase.auth.FirebaseAuth$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
I think this has something to do with the Firebase Authentication SDK but I am not sure.
Do you know what this is caused by? How can I solve it?
I actually figured it out, the problem was with the AuthStateListener.
So if you're having a similar issue, try testing your project with the AuthStateListener commented out and see if it launches without crashing. If it does you can then figure out how to replace the existing listener.
Hope this helps in some way!
View.startDrag throws NPE and this is happening to me for Android API 15 but not API 22.
This issue is very easy to reproduce. Open Android Studio, create a template project with one blank activity using API 15. Adding the following logic to the floating action button:
fab.setOnLongClickListener(
new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
v.startDrag(ClipData.newPlainText("", ""), new View.DragShadowBuilder(v), null, 0);
return true;
}
}
);
The stacktrace for the error is the following:
E/View: Unable to initiate drag
java.lang.NullPointerException
at android.view.Surface.lockCanvas(Surface.java:77)
at android.view.View.startDrag(View.java:13869)
at test.dragdroptest.MainActivity$2.onLongClick(MainActivity.java:59)
at android.view.View.performLongClick(View.java:3827)
at android.view.View$CheckForLongPress.run(View.java:14571)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Not sure what I did wrong here. I have been fighting this issue for two days and there is not much resource online about this. I cannot believe no one else had ran into the same issue...
Apparently, it only happens on the device I used for testing but not from emulator with the same API level. I guess there is no way I can get away from this issue :(
My android app is more than a year on Play now and everything was OK.
About 2 weeks ago users started complaining on crashes. Than was strange cause I haven't changed anything for some time now.
Yesterday, after finally taking a look on crash logs, I've noticed huge number NoClassDefFoundError being thrown, which led to crashes in the app.
3 strange things:
1) GameplayFragment$TimerUpdater is of course present.
1) The app has not been updated for months.
2) Apparently only GINGERBREAD versions crash
Has anybody experienced this?
Thanks
[main] java.lang.NoClassDefFoundError: com.ivygames.morskoiboi.ui.GameplayFragment$TimerUpdater at
com.ivygames.morskoiboi.ui.GameplayFragment.startTimer(GameplayFragment.java:336) at
com.ivygames.morskoiboi.ui.GameplayFragment.access$10(GameplayFragment.java:333) at
com.ivygames.morskoiboi.ui.GameplayFragment$UiProxy$1.run(GameplayFragment.java:495) at
android.os.Handler.handleCallback(Handler.java:587) at
android.os.Handler.dispatchMessage(Handler.java:92) at
android.os.Looper.loop(Looper.java:130) at
android.app.ActivityThread.main(ActivityThread.java:3691) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:507) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) at
dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassNotFoundException: com.ivygames.morskoiboi.ui.GameplayFragment$TimerUpdater in loader dalvik.system.PathClassLoader[/data/app/com.ivygames.morskoiboi-1.apk] at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) at
java.lang.ClassLoader.loadClass(ClassLoader.java:551) at
java.lang.ClassLoader.loadClass(ClassLoader.java:511) ... 12 more (BOARD=codina; BOOTLOADER=unknown; BRAND=samsung; CPU_ABI=armeabi-v7a; DEVICE=GT-I8160; DISPLAY=GINGERBREAD.XXLL2; HARDWARE=samsung; HOST=DELL205; ID=GINGERBREAD; MANUFACTURER=samsung; MODEL=GT-I8160; PRODUCT=GT-I8160; USER=dpi; SDK=10)
Please see minimum sdk version required you can set it to lower android version i.e 7 or 8
This one is driving me and my team completely crazy.
We can't reproduce as it works well on all our test devices but we are getting thousands of crash reports complaining of java.lang.NullPointerException for a TextView which is obtained by findViewById in onCreate (after calling setContentView and with the correct id and layout file)
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxxxxxxxxxxxx.activities.PremiumActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at xxxxxxxxx.activities.PremiumActivity.onCreate(PremiumActivity.java:258)
at android.app.Activity.performCreate(Activity.java:5163)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(NativeStart.java)
Here is the onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.premium_activity_layout);
premiumInfoHeaderTextView = (TextView) findViewById(R.id.premiumHeaderTextView);
int themeColor = MPThemeManager.getSharedInstance(this).themeColor();
premiumInfoHeaderTextView.setTextColor(themeColor);
That last line is the one causing the nullPointerException (line 258)
Not sure if it can be related but the activity extends SherlockFragmentActivity
And of course premiumInfoHeaderTextView is declared as a TextView outside the onCreate method as we also use it elsewhere.
A crazy fix to a crazy bug!!
As expected in my earlier comment, the bug comes from the fact the an old layout xml file for tablets (under /res/layout-large) has beed removed in our latest version (we now use a single layout file under /res/layout).
Remember the line causing the Null Exception:
premiumInfoHeaderTextView = (TextView) findViewById(R.id.premiumHeaderTextView);
This is due to the fact that our former version layout did not have any view with id = premiumHeaderTextView and that on some tablets for users who upgraded from the previous to the new version, the old layout file has not been deleted and the system is therefore looking for id in the old /res/layout-large/premium_activity_layout.xml rather than in the new (common to all devices) /res/layout/premium_activity_layout.xml
Using crashlytics to understand that all crashes were happening on tablet devices was key to identify this "bug" which seems like a system bug on some tablets as they should not keep old resource files when the apk is upgrade.
So in summary, I copied the /res/layout/premium_activity_layout.xml to /res/layout-large in order to force tablet users to use the new layout and not an old "cached" version. That has completely fixed the bug
I have the following Android exception. It is reported by Bugsense and I cannot find out where it comes from as there is no reference to any class of my app.
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
at android.widget.AbsListView$ListItemAccessibilityDelegate.onInitializeAccessibilityNodeInfo(AbsListView.java:2512)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:4849)
at android.widget.LinearLayout.onInitializeAccessibilityNodeInfo(LinearLayout.java:1768)
at android.view.View.createAccessibilityNodeInfo(View.java:4812)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:825)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchDescendantsOfRealNode(AccessibilityInteractionController.java:848)
at android.view.AccessibilityInteractionController$AccessibilityNodePrefetcher.prefetchAccessibilityNodeInfos(AccessibilityInteractionController.java:734)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:205)
at android.view.AccessibilityInteractionController.access$400(AccessibilityInteractionController.java:49)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:985)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
I do suspect it has something to do with updating a widget. Any ideas on how to trace?
Got similar Nullpointer with a Google map view.
try and turn off any accessibility options enabled on your phone?
And there is a another accessibility bug reported on the Android Issues tracker here
It looks like there is no easy way to turn of accessibility from code, except for overriding the addChildrenForAccessibility method in a custom view. (see above link)