Out of memory. InflateException Binary XML file Android - android

I have OutOfMemoryError while creating layout with a few images.
In line where logcat show me error i start declare TextView.
Error is on Samsung Galaxy S4.
When i run apps on HTC Desire X there is no error.
What might be the cause of that and how can i fix this.
10-21 18:32:19.243: E/dalvikvm-heap(20015): Out of memory on a 15822016-byte allocation.
10-21 18:32:19.243: I/dalvikvm(20015): "main" prio=5 tid=1 RUNNABLE
10-21 18:32:19.243: I/dalvikvm(20015): | group="main" sCount=0 dsCount=0 obj=0x41d6cea0 self=0x41d5b538
10-21 18:32:19.243: I/dalvikvm(20015): | sysTid=20015 nice=0 sched=0/0 cgrp=apps handle=1074303316
10-21 18:32:19.243: I/dalvikvm(20015): | state=R schedstat=( 0 0 0 ) utm=235 stm=203 core=2
10-21 18:32:19.243: I/dalvikvm(20015): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-21 18:32:19.243: I/dalvikvm(20015): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
10-21 18:32:19.243: I/dalvikvm(20015): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
10-21 18:32:19.243: I/dalvikvm(20015): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
10-21 18:32:19.243: I/dalvikvm(20015): at android.content.res.Resources.loadDrawable(Resources.java:3056)
10-21 18:32:19.243: I/dalvikvm(20015): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-21 18:32:19.253: I/dalvikvm(20015): at android.view.View.<init>(View.java:3694)
10-21 18:32:19.263: I/dalvikvm(20015): at android.widget.TextView.<init>(TextView.java:898)
10-21 18:32:19.263: I/dalvikvm(20015): at android.widget.TextView.<init>(TextView.java:893)
10-21 18:32:19.263: I/dalvikvm(20015): at java.lang.reflect.Constructor.constructNative(Native Method)
10-21 18:32:19.263: I/dalvikvm(20015): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
10-21 18:32:19.263: I/dalvikvm(20015): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10-21 18:32:19.263: I/dalvikvm(20015): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10-21 18:32:19.263: I/dalvikvm(20015): at com.example.fragments.LocalApiFragment.onCreateView(LocalApiFragment.java:40)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-21 18:32:19.263: I/dalvikvm(20015): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-21 18:32:19.263: I/dalvikvm(20015): at android.os.Handler.handleCallback(Handler.java:733)
10-21 18:32:19.263: I/dalvikvm(20015): at android.os.Handler.dispatchMessage(Handler.java:95)
10-21 18:32:19.263: I/dalvikvm(20015): at android.os.Looper.loop(Looper.java:157)
10-21 18:32:19.263: I/dalvikvm(20015): at android.app.ActivityThread.main(ActivityThread.java:5356)
10-21 18:32:19.263: I/dalvikvm(20015): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:32:19.263: I/dalvikvm(20015): at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:32:19.263: I/dalvikvm(20015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-21 18:32:19.263: I/dalvikvm(20015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-21 18:32:19.263: I/dalvikvm(20015): at dalvik.system.NativeStart.main(Native Method)
10-21 18:32:19.263: D/skia(20015): --- allocation failed for scaled bitmap
10-21 18:32:19.263: D/AndroidRuntime(20015): Shutting down VM
10-21 18:32:19.263: W/dalvikvm(20015): threadid=1: thread exiting with uncaught exception (group=0x41d6bda0)
10-21 18:32:19.263: E/AndroidRuntime(20015): FATAL EXCEPTION: main
10-21 18:32:19.263: E/AndroidRuntime(20015): Process: com.example, PID: 20015
10-21 18:32:19.263: E/AndroidRuntime(20015): android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
10-21 18:32:19.263: E/AndroidRuntime(20015): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
10-21 18:32:19.263: E/AndroidRuntime(20015): at com.example.fragments.LocalApiFragment.onCreateView(LocalApiFragment.java:40)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:450)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.os.Handler.handleCallback(Handler.java:733)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.os.Handler.dispatchMessage(Handler.java:95)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.os.Looper.loop(Looper.java:157)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.app.ActivityThread.main(ActivityThread.java:5356)
10-21 18:32:19.263: E/AndroidRuntime(20015): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015): at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:32:19.263: E/AndroidRuntime(20015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
10-21 18:32:19.263: E/AndroidRuntime(20015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
10-21 18:32:19.263: E/AndroidRuntime(20015): at dalvik.system.NativeStart.main(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015): Caused by: java.lang.reflect.InvocationTargetException
10-21 18:32:19.263: E/AndroidRuntime(20015): at java.lang.reflect.Constructor.constructNative(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
10-21 18:32:19.263: E/AndroidRuntime(20015): ... 23 more
10-21 18:32:19.263: E/AndroidRuntime(20015): Caused by: java.lang.OutOfMemoryError
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.content.res.Resources.loadDrawable(Resources.java:3056)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.view.View.<init>(View.java:3694)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.widget.TextView.<init>(TextView.java:898)
10-21 18:32:19.263: E/AndroidRuntime(20015): at android.widget.TextView.<init>(TextView.java:893)
10-21 18:32:19.263: E/AndroidRuntime(20015): ... 26 more

Your bitmap is too heavy. Resize it(e.g gimp) and try again.

I've stumble upon this problem too in most of HiDef devices such as Galaxy S4. It's because HiDef devices use xhdpi, xxhdpi and so on to inflate drawable. When they didn't find it, they scale it programmatically thus cause OutOfMemory Exception. So the solution is to put your drawable on those hdpi, xhdpi, xxhdpi, xxhdpi folder accordingly.
samsung helpdesk source

Related

UnsatisfiedLinkError: Native method not found with .so file correctly put in Eclipse libs

I'm new in using native methods for Android. I got the errors as below even after I have make sure my armeabi, armeabi-v7a, mips and x86 with correct *.so file are put correctly in the folders.
10-21 18:51:36.685: E/AndroidRuntime(24277): java.lang.UnsatisfiedLinkError: Native method not found: com.arzap.mimas.MimasJNI.MIMAS_LoadModel:(Ljava/lang/String;)V
10-21 18:51:36.685: E/AndroidRuntime(24277): at com.arzap.mimas.MimasJNI.MIMAS_LoadModel(Native Method)
10-21 18:51:36.685: E/AndroidRuntime(24277): at com.arzap.mimas.ar.MainActivity.onCreate(MainActivity.java:36)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.Activity.performCreate(Activity.java:5451)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.access$900(ActivityThread.java:175)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.os.Handler.dispatchMessage(Handler.java:102)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.os.Looper.loop(Looper.java:146)
10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.main(ActivityThread.java:5602)
10-21 18:51:36.685: E/AndroidRuntime(24277): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:51:36.685: E/AndroidRuntime(24277): at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:51:36.685: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
10-21 18:51:36.685: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
10-21 18:51:36.685: E/AndroidRuntime(24277): at dalvik.system.NativeStart.main(Native Method)
As below is how I loaded my .so file:
static{
try {
System.loadLibrary("libMimasAr3D");
} catch (UnsatisfiedLinkError use) {
Log.e("JNI", "WARNING: Could not load libMimasAr3D.so");
}
}
Something extra (which I don't think that's the main issue)?
In the same file where I load my library, I have this method:
public static native void MIMAS_LoadModel(int ppModel);
Main Activity.java:
//Description: Load the model.
//Input: pModelPath - A file path to the saved model.
//Return: A pointer to the object of the model. NULL if loading is failed.
//Load image to MIMAS_SDK
MimasJNI.MIMAS_LoadModel("models/model.bin");
Kindly please help me with that. Thanks in advance!
loadLibrary() takes the name without "lib" prefix.
If you don't use RegisterNatives(), you should name the exported functions of your native library according to javah prescriptions, e.g. Java_com_arzap_mimas_MimasJNI_MIMAS_1LoadModel.
If the native code is C++, make sure the exported functions have extern "C" prefix to pervent name mangling.

InflateException i have an Error inflating class

I have more activities and i dont have any problem but when i'm starting this activity(Segunda) it break
In this Activity I try to use a customView for zoom and draw, and i cant find where is the problem
this is the activity
public class Segunda extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_segunda);
//setContentView(new Panel(this));
setContentView(R.layout.activity_segunda);
}
}
this is the xml layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.andres.sun4all.Panel
android:id="#+id/Panelillo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight = "2">
</LinearLayout>
Logcat:
10-21 12:43:58.191: E/AndroidRuntime(27794): FATAL EXCEPTION: main
10-21 12:43:58.191: E/AndroidRuntime(27794): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.andres.sun4all/com.andres.sun4all.Segunda}: android.view.InflateException: Binary XML file line #7: Error inflating class com.andres.sun4all.Panel
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread.access$600(ActivityThread.java:140)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.os.Handler.dispatchMessage(Handler.java:99)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.os.Looper.loop(Looper.java:137)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread.main(ActivityThread.java:4898)
10-21 12:43:58.191: E/AndroidRuntime(27794): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 12:43:58.191: E/AndroidRuntime(27794): at java.lang.reflect.Method.invoke(Method.java:511)
10-21 12:43:58.191: E/AndroidRuntime(27794): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
10-21 12:43:58.191: E/AndroidRuntime(27794): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
10-21 12:43:58.191: E/AndroidRuntime(27794): at dalvik.system.NativeStart.main(Native Method)
10-21 12:43:58.191: E/AndroidRuntime(27794): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.andres.sun4all.Panel
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.createView(LayoutInflater.java:596)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-21 12:43:58.191: E/AndroidRuntime(27794): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.Activity.setContentView(Activity.java:1924)
10-21 12:43:58.191: E/AndroidRuntime(27794): at com.andres.sun4all.Segunda.onCreate(Segunda.java:13)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.Activity.performCreate(Activity.java:5206)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
10-21 12:43:58.191: E/AndroidRuntime(27794): ... 11 more
10-21 12:43:58.191: E/AndroidRuntime(27794): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
10-21 12:43:58.191: E/AndroidRuntime(27794): at java.lang.Class.getConstructorOrMethod(Class.java:460)
10-21 12:43:58.191: E/AndroidRuntime(27794): at java.lang.Class.getConstructor(Class.java:431)
10-21 12:43:58.191: E/AndroidRuntime(27794): at android.view.LayoutInflater.createView(LayoutInflater.java:561)
10-21 12:43:58.191: E/AndroidRuntime(27794): ... 22 more
thanks for your help!
Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
it means that your custom view Panel is missing the constructor with the context and attributeset:
public void Panel(Context context, AttributeSet att) {
super(context,att)
}
which is used when the custom view is inflated from the xml

Android project crashes whenever a Maps fragment is in the layouts xml

I'm currently trying to build an app with Google Map APIv2 for Android. I have spent a few hours trying to debug this error and have found nothing. I even tried creating
All I ever get when I try to include maps API fragment is "Unfortunately, myapp has"
LogCat
10-21 02:13:05.563: D/dalvikvm(2183): GC_FOR_ALLOC freed 61K, 4% free 3523K/3660K, paused 0ms, total 15ms
10-21 02:13:05.643: D/(2183): HostConnection::get() New Host Connection established 0xb8207700, tid 2183
10-21 02:13:05.663: W/EGL_emulation(2183): eglSurfaceAttrib not implemented
10-21 02:13:05.663: D/OpenGLRenderer(2183): Enabling debug mode 0
10-21 02:13:05.683: D/dalvikvm(2183): GC_FOR_ALLOC freed 99K, 5% free 3886K/4064K, paused 4ms, total 4ms
10-21 02:13:12.003: D/AndroidRuntime(2183): Shutting down VM
10-21 02:13:12.003: W/dalvikvm(2183): threadid=1: thread exiting with uncaught exception (group=0xb0cb0b20)
10-21 02:13:12.013: E/AndroidRuntime(2183): FATAL EXCEPTION: main
10-21 02:13:12.013: E/AndroidRuntime(2183): Process: com.example.myapp, PID: 2183
10-21 02:13:12.013: E/AndroidRuntime(2183): java.lang.IllegalStateException: Could not execute method of the activity
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.View$1.onClick(View.java:3823)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.View.performClick(View.java:4438)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.View$PerformClick.run(View.java:18422)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.os.Handler.handleCallback(Handler.java:733)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.os.Handler.dispatchMessage(Handler.java:95)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.os.Looper.loop(Looper.java:136)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.reflect.Method.invoke(Method.java:515)
10-21 02:13:12.013: E/AndroidRuntime(2183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-21 02:13:12.013: E/AndroidRuntime(2183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-21 02:13:12.013: E/AndroidRuntime(2183): at dalvik.system.NativeStart.main(Native Method)
10-21 02:13:12.013: E/AndroidRuntime(2183): Caused by: java.lang.reflect.InvocationTargetException
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.reflect.Method.invoke(Method.java:515)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.View$1.onClick(View.java:3818)
10-21 02:13:12.013: E/AndroidRuntime(2183): ... 11 more
10-21 02:13:12.013: E/AndroidRuntime(2183): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-21 02:13:12.013: E/AndroidRuntime(2183): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.Activity.setContentView(Activity.java:1929)
10-21 02:13:12.013: E/AndroidRuntime(2183): at com.example.myapp.MainActivity.onClick_Login(MainActivity.java:51)
10-21 02:13:12.013: E/AndroidRuntime(2183): ... 14 more
10-21 02:13:12.013: E/AndroidRuntime(2183): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.Fragment.instantiate(Fragment.java:597)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.Fragment.instantiate(Fragment.java:561)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.Activity.onCreateView(Activity.java:4778)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
10-21 02:13:12.013: E/AndroidRuntime(2183): ... 21 more
10-21 02:13:12.013: E/AndroidRuntime(2183): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.MapFragment" on path: DexPathList[[zip file "/data/app/com.example.myapp.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.myapp-2, /vendor/lib, /system/lib]]
10-21 02:13:12.013: E/AndroidRuntime(2183): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
10-21 02:13:12.013: E/AndroidRuntime(2183): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
10-21 02:13:12.013: E/AndroidRuntime(2183): at android.app.Fragment.instantiate(Fragment.java:583)
10-21 02:13:12.013: E/AndroidRuntime(2183): ... 24 more
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="HIDDEN" />
</application>
</manifest>
activity
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/buttonLogout" />
<Button
android:id="#+id/buttonLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="onClick_Logout"
android:text="Logout" />
</RelativeLayout>

android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>

I am developing a simple android apllication and just completed the home screen. Now if the orientation of the screen changes more than two times, it is throwing the error and application is getting crashed abrubptly.
Here is my Java Class:
public class PasswordActivity extends Activity implements OnClickListener {
Button login;
Button forgot;
Button register;
private static final String PREFERENCES = "prefs";
private static final String PREFERENCES_NAME = "pref_name";
SharedPreferences settings;
private Cursor c;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
login=(Button)findViewById(R.id.login_login);
login.setOnClickListener(this);
register=(Button)findViewById(R.id.login_register);
register.setOnClickListener(this);
}
public void onClick(View v) {
}
}
And this is my Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/listpic">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<TextView
android:layout_width="fill_parent"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:text="#string/login_user_name"
android:textStyle="bold"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:id="#+id/login_user_name"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<TextView
android:layout_width="fill_parent"
android:layout_weight="0.75"
android:layout_height="wrap_content"
android:text="#string/login_password"
android:textStyle="bold"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:inputType="textPassword"
android:id="#+id/login_password"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<Button
style="#style/left_button"
android:text="#string/login_submit"
android:id="#+id/login_login"/>
<Button
style="#style/right_button"
android:id="#+id/login_register"
android:text="#string/register"/>
</LinearLayout>
</LinearLayout>
Log Cat Details:
10-21 12:05:59.982: D/dalvikvm(622): GC_EXTERNAL_ALLOC freed 774 objects / 56240 bytes in 61ms
10-21 12:06:15.031: D/dalvikvm(622): GC_EXTERNAL_ALLOC freed 737 objects / 30992 bytes in 59ms
10-21 12:06:18.022: E/dalvikvm-heap(622): 7596000-byte external allocation too large for this process.
10-21 12:06:18.022: E/GraphicsJNI(622): VM won't let us allocate 7596000 bytes
10-21 12:06:18.043: D/AndroidRuntime(622): Shutting down VM
10-21 12:06:18.043: W/dalvikvm(622): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-21 12:06:18.092: E/AndroidRuntime(622): FATAL EXCEPTION: main
10-21 12:06:18.092: E/AndroidRuntime(622): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ravi.password/com.ravi.password.PasswordActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-21 12:06:18.092: E/AndroidRuntime(622): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-21 12:06:18.092: E/AndroidRuntime(622): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622): at java.lang.reflect.Method.invoke(Method.java:521)
10-21 12:06:18.092: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-21 12:06:18.092: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-21 12:06:18.092: E/AndroidRuntime(622): at dalvik.system.NativeStart.main(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
10-21 12:06:18.092: E/AndroidRuntime(622): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-21 12:06:18.092: E/AndroidRuntime(622): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.app.Activity.setContentView(Activity.java:1647)
10-21 12:06:18.092: E/AndroidRuntime(622): at com.ravi.password.PasswordActivity.onCreate(PasswordActivity.java:34)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-21 12:06:18.092: E/AndroidRuntime(622): ... 12 more
10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: java.lang.reflect.InvocationTargetException
10-21 12:06:18.092: E/AndroidRuntime(622): at android.widget.LinearLayout.<init>(LinearLayout.java:115)
10-21 12:06:18.092: E/AndroidRuntime(622): at java.lang.reflect.Constructor.constructNative(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
10-21 12:06:18.092: E/AndroidRuntime(622): ... 22 more
10-21 12:06:18.092: E/AndroidRuntime(622): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.Bitmap.nativeCreate(Native Method)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
10-21 12:06:18.092: E/AndroidRuntime(622): at android.view.ViewGroup.<init>(ViewGroup.java:285)
10-21 12:06:18.092: E/AndroidRuntime(622): ... 26 more
Images used are of very small size around 5kb.
At runtime, Android resize's images based on need (based on the screen size and resolution). It uses Bitmap's for doing the resizing internally. Which, obviously, is very memory intensive (kinda allocates memory like crazy). One quick way to fix such issues can be, that you copy all drawable files to drawable-ldpi, mdpi, hdpi folders. This way android will just pick up the files from these folders and not resize them.
Its a random kind exception, a real pain to fix.
please follow background image size
for Supported device
LDPI:
Portrait: 200x320px
Landscape: 320x200px
MDPI:
Portrait: 320x480px
Landscape: 480x320px
HDPI:
Portrait: 480x800px
Landscape: 800x480px
XHDPI:
Portrait: 720px1280px
Landscape: 1280x720px
Sorry for my bad English
I had the same problem, if you put any "xml" files into "drawable-24" just move them to "drawable", this was the solution that i did to solve this problem
have a nice day :)
As the others clarified, part of a problem was an issue related to the background image I'd set for my layout. However, getting that solved, I persistently encountered the error:
Unfortunately the application has stopped
With trial and error, I found the problem was caused by the <view> elements which after deleting them, I could eventually run the application.

Make Commonsware TouchListView functional in a TabGroup activity

when I run my project with the Commonsware TouchListView inside a TabGroupActivity, I can see the ListView but when I try to Drag an item the app crashes. I have this in the log :
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): FATAL EXCEPTION: main
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord#4099bfd0 is not valid; is your activity running?
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewRoot.setView(ViewRoot.java:527)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.commonsware.cwac.tlv.TouchListView.startDragging(TouchListView.java:419)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.commonsware.cwac.tlv.TouchListView.onInterceptTouchEvent(TouchListView.java:176)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:848)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.os.Handler.dispatchMessage(Handler.java:99)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.os.Looper.loop(Looper.java:130)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at java.lang.reflect.Method.invoke(Method.java:507)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-21 11:21:50.433: ERROR/AndroidRuntime(23139): at dalvik.system.NativeStart.main(Native Method)
I do not support activities-in-tabs for any of the CWAC components. It is an officially deprecated technique. It was never a very good idea in the first place, IMHO.
The TouchListView code comes from an Android open source application that does not use tabs in the activity with the drag-and-drop. The technique it uses for the drag indicator -- adding it as a view to the Window -- probably does not work for activities-in-tabs. It may work if you set up your tabs to have views as their contents, as you can see in this sample project.

Categories

Resources