I know that there are a million other questions on OutOfMemoryError on SO. But my case is different. None of the lines in the stack trace is from my code or a library that I have included. Whole of the stack trace consists of Android's standard libraries.
I don't have any clue as to where I should start my debugging. Any ideas on how I should debug it further?
Fatal Exception: java.lang.OutOfMemoryError
at android.util.ArrayMap.allocArrays(ArrayMap.java:196)
at android.util.ArrayMap.ensureCapacity(ArrayMap.java:307)
at android.os.Bundle.unparcel(Bundle.java:247)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1273)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1207)
at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(FragmentManager.java:2323)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2136)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2092)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1998)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:709)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(NativeStart.java)
android/app/src/main/AndroidManifest.xml
<application
android:largeHeap="true"
Adding largeHeap might be fix it
Related
I've been using android studio for a while and whenever an exception occurs the information shown in the stacktrace does not contain the class in which the error occured or the line number. It is not even colored blue like it is supposed to. Here's an example of a stacktrace that is thrown:
ava.lang.StringIndexOutOfBoundsException: length=2; index=3
at java.lang.String.indexAndLength(String.java:579)
at java.lang.String.substring(String.java:1438)
at com.patriceandala.myapplication.utils.D.a(SourceFile:101)
at com.patriceandala.myapplication.utils.D.a(SourceFile:29)
at com.patriceandala.myapplication.utils.B.a(SourceFile:77)
at d.b.a.a.run(SourceFile:46)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
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:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
It only shows 'SourceFile' yet I don't have a class with that name. How can I fix this?
Disable ProGuard in debug mode and check.
Proguard is a free Java class file shrinker, optimizer, obfuscator and preverifier. It makes the code unreadable. So disable this in debug mode.
I have been working on a project that has been perfectly fine, until i included the android-smack-xmpp library.
After this inclusion, i am not able to run the app on devices (API < 21) on debug mode. However i am able to run it on release build variant.
Process: com.example, PID: 496
java.lang.NoClassDefFoundError: com.example.network.ServerCalls$3
at com.example.network.ServerCalls.initData(ServerCalls.java:167)
at com.example.ui.fragmentsAndActivities.homeFeed.HomePageActivity.onCreate(HomePageActivity.java:212)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
ServerCalls is included in the HomePageActivity, and compilation works just fine. What is that i could be missing here ?
Also HomePageActivity.java:212 is :
ServerCalls.samosaInitData()
Edit : I have been able to get it working my setting minifyEnabled and shrinkResources to true in gradle for the debug build. This is probably pointing at improper linking in the JVM. But this looks like a hack to me. Can somebody point me to a cleaner way of doing the same?
The error was multi-dexing the solution.
The smack-api library introduction led to the 64k dex limit to be exceeded.
Multidexing the solution does the trick.
It looks like you don't export your library in the final .apk file.
You have to choose the Compile option in your Android Studio project settings in the Dependencies section.
I am not an Android developer, but I am trying to upgrade the Facebook SDK for an app I have on Android Studio. The previous SDK was 3.5 and I am trying to add 4.4.1
I have written the login class by following the getting started guide but now when I try to launch the app on a device, although it compiles just fine, it crashes on startup.
I get the following error:
08-05 21:05:25.128 25207-25207/? E/dalvikvm﹕ Could not find class
'com.history.HistoryOrder', referenced from method
com.service.Global. 08-05 21:05:25.138 25207-25207/?
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.imperautus.testProject.ActivitySplash.onCreate(ActivitySplash.java:61)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.access$700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.history.HistoryOrder
at com.service.Global.(Global.java:113)
at com.imperautus.testProject.ActivitySplash.onCreate(ActivitySplash.java:61)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.access$700(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
What I see is that it complaints that it cannot find the class com.history.HistoryOrder but this class is in this exact place and it worked before the transition to the new Facebook SDK (I haven't touched the class' code).
The Global.java:113 says:
public static ArrayList<HistoryOrder> historyOrderList = new ArrayList<HistoryOrder>();
public static HistoryOrder historyOrderItem = new HistoryOrder();
I also changed all references in my code from app.Fragment to the support.v4.app.Fragment version because I thought that this caused the problem.
Any clues?
java.lang.NoClassDefFoundError is propably thrown because you have reached the 65k limit http://developer.android.com/tools/building/multidex.html#about
If you need to go beyond 65k limit you must include multidex support
gradle:
defaultConfig {
...
multiDexEnabled true
}
...
dependencies {
compile 'com.android.support:multidex:1.0.1'
...
}
Manifest:
<application
...
android:name="android.support.multidex.MultiDexApplication">
If you have a Custom Application class:
extend MultiDexApplication or add MultiDex.install(getBaseContext()); to your CustomApplication onCreate()
Note that on some low-end devices adding
MultiDex.install(getBaseContext()); to your CustomApplication onCreate()
can still throw java.lang.NoClassDefFoundError:
If so try adding MultiDex.install to attachBaseContext(Context base) instead
public class CustomApplication extends Application {
...
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
...
ok, it seems that the error was due to a very different reason:
The app was updated to use Google Services 7.5 which made the methods go to more than 65k which made me to add the mutiDexEnabled to true.
I don't know if the code needs to be changed to support that, but it seems that after making this change, the app was crashing at random points (when I remarked the history call, the reachability class was crashing, when removed the reachability another, etc.
of course all classes were at the right place when the compiler complained about not finding them
This made me wonder if the multidex caused that so I removed some of the libraries like going from 7.5 verson of google play to 6.5
The app compiles and runs just fine now, allowing me to add the FB sdk 4+
I post this here, so it may help other people having problems without being able to understand where they come from.
I think you set the wrong class path so 1st check your class path
It will solve your problem
My Activity extends from MapActivity, I have descried it correctly in the manifest, I have put the <uses-library> tag inside the <application> tag I am building with goole apis library and the maps.jar is there only one time(no duplicates) and the app runs and works perfect on most devices.
However I got a crash report with ClassDefNotFoundException which occurred on ZTE Blade device with Android 2.1. I am building with google apis 2.1
Does anyone have suggestions for that?
I am providing the stack trace too:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2165)
at android.view.View.performClick(View.java:2506)
at android.view.View$PerformClick.run(View.java:9112)
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:3835)
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:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2160)
... 11 more
Caused by: java.lang.NoClassDefFoundError: com.testing.asd.android.ui.InfoActivity
at com.testing.asd.android.ui.HomeScreen.onClick(HomeScreen.java:60)
... 14 more
com.testing.asd.android.ui.InfoActivity extends MapActivity. The problem is only on one device so far. I tested it on Android 2.3 and 4.2 and it is ok there.
I'm not sure if this is the case with the ZTE Blade, but there are some devices (such as the Kindle Fire) that don't have the Google APIs. I think these phones will show a NoClassDefFoundError if your app uses MapView.
So I have an app that has previously worked perfectly in Eclipse.
Since I have converted to Maven, I am getting NoClassDefFoundError when I try to start a particular activity (SliderMenuActivity).
The strange thing is that the app will start and load the main activity (StartActivity) which is the same package. Note that both activities are included in the AndroidManifest.xml
It seems that the offending piece of code is:
Intent intSliderActivity = new Intent(StartActivity.this, SliderMenuActivity.class);
Just wondering does the change to the src folder have anything to do with this?
I have also changed the source folder to look like src/main/java/com/conor/etc and updated the build path.
Any ideas on how to solve?
For reference, here is the stacktrace:
E/AndroidRuntime(25063): FATAL EXCEPTION: main
E/AndroidRuntime(25063): java.lang.NoClassDefFoundError: com.my_app.android.app.SliderMenuActivity
at com.my_app.android.app.StartActivity$6.my_appApiCallback(StartActivity.java:261)
at com.my_app.android.app.my_app_user_api.my_appApiTask.onPostExecute(my_appApiTask.java:129)
at com.my_app.android.app.my_app_user_api.my_appApiTask.onPostExecute(my_appApiTask.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
declare your class in manifest file with package name like
<activity android:name="com.example.SliderMenuActivity">
I think you did not build success LeftMenuSide library. Please try to build again