web-dev-qa-db-fra.com

android.view.InflateException: ligne de fichier XML binaire # 2: erreur de gonflement de la classe <inconnu>

Je développe une application simple. Je viens de terminer l'écran d'accueil. Si l'orientation change plus de deux fois, cela génère l'erreur et l'application se ferme de force.

Mon code d'activité:

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) {
}

}

Mon code Xml:

<?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>

Détails du chat de journal:

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 

Les images sont de très petite taille autour de 5 Ko.

22
Ravindra

Au moment de l'exécution, Android redimensionne les images en fonction des besoins (en fonction de la taille et de la résolution de l'écran). Il utilise Bitmap pour effectuer le redimensionnement en interne. Ce qui, évidemment, est très gourmand en mémoire (alloue en quelque sorte de la mémoire comme Un moyen rapide de résoudre ces problèmes peut être de copier tous les fichiers dessinables dans des dossiers drawable-ldpi, mdpi, hdpi. De cette façon Android va simplement récupérer les fichiers de ces dossiers et ne pas les redimensionner.

C'est une exception aléatoire, une vraie douleur à corriger.

67
Siddharth

veuillez suivre la taille de l'image d'arrière-plan

pour appareil pris en charge

LDPI:
Portrait: 200x320px
Landscape: 320x200px
MDPI:
Portrait: 320x480px
Landscape: 480x320px
HDPI:
Portrait: 480x800px
Landscape: 800x480px
XHDPI:
Portrait: 720px1280px
Landscape: 1280x720px
3
Mahadev Dalavi