wake-up-neo.com

InflateException: Binäre XML-Dateizeile 1: Fehler beim Aufblasen der Klasse <unbekannt>, verursacht durch OutOfMemoryError

Hier ist mein Code:

input.xml (Layoutordner)

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

    }

}

Ich kann diesen Code ordnungsgemäß ausführen, aber wenn ich die Ausrichtung des Emulators geändert habe, wird der folgende Fehler angezeigt.

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

Grundsätzlich ist der Fehler auf den folgenden Ort gerichtet:

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

Dies geschieht nur im Emulator, nicht im Telefon. Was ist hier falsch?

30

Überprüfen Sie Ihren drawable/background_main, d. H. Das Hintergrundbild Ihres Stammlayouts. Die VM hat bei der Decodierung der Bitmap keinen Speicher mehr. Verkleinern Sie die Bildabmessungen.

84
laalto

Das Problem tritt auf, weil * drawable/background_main * ein hochauflösendes Bild hat. Wenn er also lädt, hat derVM keinen Speicher mehr.

Am besten ist es also, die Größe oder Auflösung zu reduzieren.

8
Piyush

Sie verwenden dieses Layout in Fragment und nicht in Aktivität. Außerdem gibt es eine weitere Ausnahme: OutOfMemory Ihr Hintergrundbild ist sehr groß. Versuchen Sie, es zu reduzieren.

3
kalyan pvs

Verursacht durch: Java.lang.OutOfMemoryError: Die Bitmap-Größe überschreitet das VM - Budget. Verwenden Sie ein kleineres Bild, um zu sehen, ob es sich um ein speicherbezogenes Problem handelt. __ Überprüfen Sie diese Links auf Beispiele für ähnliche Probleme:

Java.lang.OutOfMemoryError: Die Bitmap-Größe überschreitet das VM - Budget. - Android - Wie viele Bilder? und OutOfMemory-Ausnahme beim Laden der Bitmap aus externem Speicher

2
M D

Mein Problem war, dass ich eine Form mit einem <solid> mit der Farbe ?selectableItemBackground hatte. Ja, es ist dumm und ein spezieller Fall, aber hier für Leute mit dem gleichen Fehler veröffentlicht.

2
jobbert

Ich habe das gleiche Problem gelöst, indem ich die Größe der .png-Schaltflächen in allen XML-Dateien reduziert habe

1
Ivan Aracki

Verwenden Sie Bilder mit unterschiedlichen Auflösungen wie mdpi, hdpi, xhdpi. Wenn Sie nur Bilder mit höherer Auflösung verwenden, kann dies bei Handys mit niedriger Auflösung zum Absturz führen

1
Tushar Saha

Nun, in meinem Fall war die Antwort im XML-Design, Konflikt Android: backgroundTint und Android: Tint

Ich habe einen FloatinActionButton so entworfen:

<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" />

und es ist ok, aber API> 23

Wenn Sie für API_LEVEL <23 entwerfen, ist dies der Fix

<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"/>

Ich hoffe ich habe dir geholfen

Grüße

In meinem Fall bekam ich unlogische Ausnahmen bei der Klasseninflation. Nachdem ich eine Zeitlang gegraben hatte, stellte ich fest, dass der Fehler auf veraltete Codeblöcke im Zusammenhang mit dem Android-Framework selbst zurückzuführen war.

0
Pratik Mhatre