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
Related
So I've been working on an app lately which runs fine on most devices. However, sometimes the app crashes at start up with the following error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mypackage.app/com.mypackage.app.activities.MainPager}:
java.lang.ClassNotFoundException: com.mypackage.app.activities.MainPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
com.mypackage.app.activities.MainPager
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1986)
... 12 more
I get that this is because it can't find the class called MainPager. But how is that even possible? I mean, the class should be there.. I put it there myself :) . Why on earth is it not finding it?
EDIT: I think the cause may be that in my manifest I have android:package="com.mypackage.app" defined, but that my launch activity is in the package com.mypackage.app.activities. Currently testing this theory. Still weird that it only happens on some devices, though.
This solution won't work, since I then can't update the APK in Google Play (has to be the same package name in the manifest).
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
in the manifest you add Activity name like this
android:name=".activities.MainPager"
because you have given package name
android:package="com.mypackage.app"
Now I am using ART runtime on Nexus 5, and I am getting ClassNotFound for some apps.
You can safely ignore those if that's the case for your users.
I uploaded an Android Application to the market, and, for some reason a user is getting this error.
java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
at android.os.Parcel.readException(Parcel.java:1331)
at android.os.Parcel.readException(Parcel.java:1281)
at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:664)
at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:3594)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1193)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2450)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4444)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)
I am pretty sure I never use WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG as referenced in other postings. I do however, have a window that switches between WindowManager.LayoutParams.TYPE_PHONE and WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY. Which seems like it could be the error. I would prefer not changing this as it would require me to have two windows instead of just one. Thanks in advance!
check AndroidManifest.xml
<uses-sdk //************
android:targetSdkVersion="X"/>
X must be less than 14 Or remove this attribute.
good luck guy.
java.lang.NoClassDefFoundError occured at the first line:
FirstFragment firstTab = FirstFragment.newInstance(10);
mTabsAdapter.addTab(generateTabSpec(0, mTabHost),
firstTab.getClass(), null);
But I'm pretty sure the Fragment exist! (it's a fragment so don't need to check if declared in Manifest.) Even refactoring its name or move to other package didn't fix the problem. Here's the stacktrace:
ERROR/AndroidRuntime(23608): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: dev.twothree.android.wtf.FirstFragment
at dev.twothree.android.activity.FragmentTab.setupTabHost(FragmentTab.java:110)
at dev.twothree.android.activity.FragmentTab.onCreate(FragmentTab.java:75)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2207)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4899)
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:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Is it a bug of Intell J 12.0.4? My version is Build #IC-123.169. Later I'll try it in the Eclipse, but still hope it can be resolved in Intelli J.
After open the whole project with Eclipse, config all the dependencies ONCE AGAIN, Eclipse point out that I accidentally CAST one of the custom library class to another class. Maybe that's why no successful compiled class file existed for later invoke.
Anyway, it seems Intelli-J didn't found that error while 3rd party library is involved, it could be a bug. But the blame is also on me for not find that so obvious error.
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.
In android, is it possible to create a GridLayout from the support library entirely programmatically (i.e. without writing corresponding xml)?
I create my GridLayout in a fragment (called PromotionLayoutFragment) like this:
ViewGroup fragmentView = (ViewGroup)getView();
GridLayout gridLayout = new GridLayout(fragmentView.getContext());
gridLayout.setColumnCount(2);
gridLayout.setRowCount(15);
// add views to grid ...
fragmentView.addView(gridLayout);
This works fine when i use the GridLayout class present in API level 14, but when I use the GridLayout from the support library (v7-r9), i get:
08-10 15:54:52.209: ERROR/AndroidRuntime(14687): FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
at android.support.v7.widget.GridLayout.<init>(GridLayout.java:282)
at net.link.redbutton.fragment.PromotionLayoutFragment.showPromotions(PromotionLayoutFragment.java:168)
at net.link.redbutton.fragment.PromotionLayoutFragment.onImageResult(PromotionLayoutFragment.java:222)
at net.link.redbutton.fragment.SchedulerResponseFragment$1.onReceiveResult(SchedulerResponseFragment.java:37)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
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:4441)
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)
Turns out that you need to include the GridLayout support library as an Android library project (apklib), instead of a jar. I was using the maven Android SDK deployer, but there is currently an issue open regarding this.