web-dev-qa-db-fra.com

InflateException: ligne de fichier XML binaire n ° 1: erreur de gonflage de la classe <inconnu> provoquée par OutOfMemoryError

Voici mon code:

input.xml (dossier de disposition)

<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    xmlns:tools="http://schemas.Android.com/tools"
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    tools:context=".MainActivity"
    Android:background="@drawable/background_main" >

    <ImageView 
        Android:id="@+id/logo_image"
        Android:background="@drawable/background_green"
        Android:src="@drawable/titleimage"
        Android:layout_width="match_parent"
        Android:layout_height="50dp"
        />

    <ScrollView
        Android:id="@+id/scroller"
        Android:layout_width="fill_parent"
        Android:layout_height="wrap_content"
        Android:layout_below="@id/logo_image"
        Android:layout_marginTop="10dp"
        >

        <TableLayout
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            Android:stretchColumns="*" >

            <TableRow
                Android:id="@+id/device_type_row"
                Android:layout_width="fill_parent"
                Android:layout_height="wrap_content"
                Android:paddingTop="5dp"
                Android:paddingBottom="5dp"
                Android:layout_marginRight="5dp" >

                <RadioButton
                    Android:id="@+id/device_type_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/device_type" />

                <RadioGroup 
                    Android:id="@+id/device_type_radio_selection"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:orientation="horizontal">

                    <RadioButton
                        Android:id="@+id/radioIos"
                        Android:layout_width="wrap_content"
                        Android:layout_height = "wrap_content"
                        Android:textAppearance="?android:attr/textAppearanceSmall"
                        Android:text="@string/iOS"
                        />

                    <RadioButton
                        Android:id="@+id/radioAndroid"
                        Android:layout_width="wrap_content"
                        Android:layout_height = "wrap_content"
                        Android:textAppearance="?android:attr/textAppearanceSmall"
                        Android:text="@string/Android"
                        />


                </RadioGroup>


            </TableRow>

            <TableRow
                Android:id="@+id/days_as_customers_row"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content"
                Android:paddingTop="5dp"
                Android:paddingBottom="5dp"
                Android:layout_marginRight="5dp" >

                <RadioButton
                    Android:id="@+id/days_as_customers_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/days_as_customers" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/days_as_customer_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/days_as_customer_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="1/210"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>

            </TableRow>

            <TableRow
                Android:id="@+id/average_sessions_row"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/average_sessions"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/average_sessions" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/average_sessions_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/average_sessions_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="240/9000"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>
            </TableRow>

            <TableRow
                Android:id="@+id/tableRow4"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/conversion_time_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/conversion_title" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/conversion_time_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/conversion_time_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="3/55"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>

            </TableRow>

            <TableRow
                Android:id="@+id/tableRow5"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/monthly_spend_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/monthly_spend" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/monthly_spend_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/monthly_spend_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="3/55"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>

            </TableRow>

            <TableRow
                Android:id="@+id/tableRow6"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/virality_invites_sent_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/virality_invites_sent" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/virality_invites_sent_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/virality_invites_sent_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="0-50"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>



            </TableRow>

            <TableRow
                Android:id="@+id/tableRow7"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/churned_users_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/churned_users" />

                <RadioGroup 
                    Android:id="@+id/churned_users_radio_selection"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:orientation="horizontal">

                    <RadioButton
                        Android:id="@+id/radioYes"
                        Android:layout_width="wrap_content"
                        Android:layout_height = "wrap_content"
                        Android:textAppearance="?android:attr/textAppearanceSmall"
                        Android:text="@string/iOS"
                        />

                    <RadioButton
                        Android:id="@+id/radioNo"
                        Android:layout_width="wrap_content"
                        Android:layout_height = "wrap_content"
                        Android:textAppearance="?android:attr/textAppearanceSmall"
                        Android:text="@string/Android"
                        />


                </RadioGroup>

            </TableRow>

            <TableRow
                Android:id="@+id/tableRow8"
                Android:layout_width="wrap_content"
                Android:layout_height="wrap_content" >

                <RadioButton
                    Android:id="@+id/ltv_total_spent_radio"
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:textAppearance="?android:attr/textAppearanceSmall"
                    Android:text="@string/ltv_total_spent" />

                <LinearLayout
                    Android:layout_width="wrap_content"
                    Android:layout_height="wrap_content"
                    Android:weightSum="2" >

                    <SeekBar
                        Android:id="@+id/ltv_total_spent_seekbar"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:layout_weight="1" />

                    <TextView
                        Android:id="@+id/ltv_total_spent_text"
                        Android:layout_width="wrap_content"
                        Android:layout_height="wrap_content"
                        Android:text="0$-80$"
                        Android:layout_weight="1"
                        Android:singleLine="true"
                        Android:textAppearance="?android:attr/textAppearanceSmall" />

                </LinearLayout>

            </TableRow>
        </TableLayout>

    </ScrollView>

    <Button
        Android:id="@+id/input_submit_button"
        Android:layout_width="wrap_content"
        Android:layout_height="wrap_content"
        Android:layout_alignParentBottom="true"
        Android:layout_centerHorizontal="true"
        Android:background="@drawable/submit_button_img" />

</RelativeLayout>

InputFragment.Java

import Android.os.Bundle;
import Android.support.v4.app.Fragment;
import Android.support.v4.app.FragmentTransaction;
import Android.view.LayoutInflater;
import Android.view.View;
import Android.view.View.OnClickListener;
import Android.view.ViewGroup;
import Android.widget.Button;
import Android.widget.RadioButton;
import Android.widget.SeekBar;
import Android.widget.SeekBar.OnSeekBarChangeListener;
import Android.widget.TextView;
import Android.widget.Toast;

public class InputFragment extends Fragment {

    private Button submit;
    private RadioButton deviceTypeRadio, daysAsCustomerRadio, averageSessionsRadio, conversionTimeRadio;
    private RadioButton monthlySpendRadio,viralityInvitesSentRadio, churnedUsersRadio, LTVTotalSpentRadio; 
    private SeekBar daysAsCustomerSeek, averageSessionSeek, conersionTimeSeek, monthlySpendSeek;
    private SeekBar viralityInvitesSeek, ltvTotalSpentSeek;
    private TextView daysasAsCustomerText, averageSessionText, conversionTimeText, monthlySpendText;
    private TextView viralityInvitesText, letvTotalText;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        //Intializing instance variables
        View view = inflater.inflate(R.layout.input, container,false);

        submit = (Button)view.findViewById(R.id.input_submit_button);

        return view;

    }

}

Je peux exécuter ce code correctement, mais lorsque j'ai modifié l'orientation de l'émulateur, l'erreur suivante s'est produite.

12-19 11:17:53.590: E/AndroidRuntime(5644): FATAL EXCEPTION: main
12-19 11:17:53.590: E/AndroidRuntime(5644): Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.nFlate.xxx.MainActivity}: Android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2180)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2230)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.handleRelaunchActivity(ActivityThread.Java:3692)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.access$700(ActivityThread.Java:141)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1240)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.os.Handler.dispatchMessage(Handler.Java:99)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.os.Looper.loop(Looper.Java:137)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.main(ActivityThread.Java:5041)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Java.lang.reflect.Method.invokeNative(Native Method)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Java.lang.reflect.Method.invoke(Method.Java:511)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:793)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:560)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at dalvik.system.NativeStart.main(Native Method)
12-19 11:17:53.590: E/AndroidRuntime(5644): Caused by: Android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.createView(LayoutInflater.Java:613)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at com.Android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.Java:56)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.onCreateView(LayoutInflater.Java:660)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.createViewFromTag(LayoutInflater.Java:685)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.inflate(LayoutInflater.Java:466)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.inflate(LayoutInflater.Java:396)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at com.nFlate.nflate.InputFragment.onCreateView(InputFragment.Java:30)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.Fragment.performCreateView(Fragment.Java:1478)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.Java:927)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.Java:1104)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.Java:1086)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.Java:1877)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.support.v4.app.FragmentActivity.onStart(FragmentActivity.Java:552)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.Instrumentation.callActivityOnStart(Instrumentation.Java:1164)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.Activity.performStart(Activity.Java:5114)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2153)
12-19 11:17:53.590: E/AndroidRuntime(5644):     ... 12 more
12-19 11:17:53.590: E/AndroidRuntime(5644): Caused by: Java.lang.reflect.InvocationTargetException
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Java.lang.reflect.Constructor.constructNative(Native Method)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Java.lang.reflect.Constructor.newInstance(Constructor.Java:417)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.LayoutInflater.createView(LayoutInflater.Java:587)
12-19 11:17:53.590: E/AndroidRuntime(5644):     ... 27 more
12-19 11:17:53.590: E/AndroidRuntime(5644): Caused by: Java.lang.OutOfMemoryError
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.graphics.BitmapFactory.decodeStream(BitmapFactory.Java:502)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.Java:355)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.graphics.drawable.Drawable.createFromResourceStream(Drawable.Java:785)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.content.res.Resources.loadDrawable(Resources.Java:1965)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.content.res.TypedArray.getDrawable(TypedArray.Java:601)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.View.<init>(View.Java:3330)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.View.<init>(View.Java:3259)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.view.ViewGroup.<init>(ViewGroup.Java:425)
12-19 11:17:53.590: E/AndroidRuntime(5644):     at Android.widget.RelativeLayout.<init>(RelativeLayout.Java:210)
12-19 11:17:53.590: E/AndroidRuntime(5644):     ... 30 more

Fondamentalement, l'erreur cible à l'endroit ci-dessous:

View view = inflater.inflate(R.layout.input, container,false);

Cela se produit uniquement dans Emulator, pas dans le téléphone. Qu'est-ce qui ne va pas ici?

30
Yohan Weerasinghe

Vérifiez votre drawable/background_main, c’est-à-dire l’image d’arrière-plan de votre mise en page racine - la VM manque de mémoire lors du décodage du bitmap. Réduisez les dimensions de l'image.

84
laalto

Le problème se produit car le * drawable/background_main * a une image haute résolution. Ainsi, lorsqu’il est chargé, leVM manque de mémoire.

Le meilleur moyen est donc de réduire la taille ou la résolution.

8
Piyush

Vous utilisez cette disposition dans le fragment et non dans Activity.End il y a aussi une autre exception OutOfMemory votre image de fond est très grande essayez de la réduire.

3
kalyan pvs

Causée par: Java.lang.OutOfMemoryError: la taille de la bitmap dépasse le budget VM peut être le véritable coupable ici. Essayez d’utiliser une image plus petite pour voir s’il s’agit d’un problème lié à la mémoire . Consultez ces liens pour des exemples de problèmes similaires:

Java.lang.OutOfMemoryError: la taille du bitmap dépasse le budget VM - Android - combien d'images? et Exception OutOfMemory lors du chargement d'un bitmap à partir d'un stockage externe

2
M D

Mon problème était que j'avais une forme avec un <solid> avec une couleur ?selectableItemBackground. Oui, c’est idiot et un cas spécifique, mais le poster ici pour les personnes avec la même erreur.

2
jobbert

J'ai résolu le même problème en réduisant la dimension des boutons .png dans tous les fichiers xml

1
Ivan Aracki

Essayez d’utiliser des images de différentes résolutions, telles que mdpi, hdpi, xhdpi. Si vous n’utilisez que des images de résolution supérieure, vous risquez de provoquer un blocage des téléphones basse résolution.

1
Tushar Saha

Eh bien, dans mon cas, la réponse était dans le design XML, conflit Android: backgroundTint et Android: teinte

Je concevais un FloatinActionButton comme ceci:

<Android.support.design.widget.FloatingActionButton
                    Android:id="@+id/fa_close_patient"
                    Android:layout_width="50dp"
                    Android:layout_height="50dp"
                    Android:scaleX="0.8"
                    Android:scaleY="0.8"
                    Android:layout_alignParentEnd="true"
                    Android:layout_centerVertical="true"
                    Android:layout_gravity="right"
                    Android:layout_marginEnd="30dp"
                    Android:backgroundTint="@color/white"
                    Android:src="@drawable/ic_close_black_24dp"
                    Android:tint="@color/colorPrimaryDark" />

et ça va mais API> 23

Si vous concevez pour API_LEVEL <23, c'est le correctif

<Android.support.design.widget.FloatingActionButton
                    Android:id="@+id/fa_close_patient"
                    Android:layout_width="50dp"
                    Android:layout_height="50dp"
                    Android:scaleX="0.8"
                    Android:scaleY="0.8"
                    Android:layout_alignParentEnd="true"
                    Android:layout_centerVertical="true"
                    Android:layout_gravity="right"
                    Android:layout_marginEnd="30dp"
                    app:backgroundTint="@color/white"
                    Android:src="@drawable/ic_close_black_24dp"/>

J'espère vous avoir aidé,

Cordialement

Dans mon cas, je recevais des exceptions illogiques d'inflation de classe, après avoir creusé pendant un moment, j'ai constaté que l'erreur était due à des blocs de code obsolètes liés au framework Android lui-même.

0
Pratik Mhatre