当前位置: 首页 > 面试题库 >

InflateException:二进制XML文件第1行:膨胀类错误 由OutOfMemoryError引起

上官霄
2023-03-14
问题内容

这是我的代码:

input.xml (布局文件夹)

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

    }

}

我可以正确运行此代码,但是当我更改仿真器的方向时,会出现以下错误。

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

基本上,该错误定位到以下位置:

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

这只会在模拟器中发生,而不会在手机中发生。怎么了


问题答案:

检查您drawable/background_main的根布局的背景图像-解码位图时,VM内存不足。缩小图像尺寸。



 类似资料:
  • 问题内容: 我使用的是Android Studio 3.0, 我已经很累解决此问题。应用程序不执行它总是向我显示此错误二进制XML文件第0行:膨胀类ImageView的错误 这是我的main_activity.xml,我更改了使用ConstraintLayout的xml 主要活动的Java代码 这是完整的日志, 问题答案: 似乎不完全支持某些SVG源。在活动的onCreate()方法中添加以下行:

  • 问题内容: 我按照http://www.techotopia.com/index.php/Using_Fragments_in_Android_- _A_Worked_Example上 的教程创建了一个应用程序,但出现错误。 LogCat: MainActivity.java: activity_main.xml: ToolbarFragment.java: toolbar_fragment.xm

  • 我很沮丧,我可能无法很好地解释,但基本上我试图编码一个音乐应用程序播放器,但每当我点击按钮,应用程序只是崩溃。Logcat真的帮不了什么忙,因为我不知道它出了什么问题。请帮帮我 主要活动。Java语言 } activity_main.xml: 登录。java:“ }" activity_login.xml:" 错误:

  • 我正在尝试遵循Maps API指南,但我已经出现此错误一段时间了。我已经尝试过: android.view.InflateException:二进制XML文件:inflating类片段错误 这是我的xml代码 这是我的主要活动

  • 问题内容: 我在运行问答游戏时出错。这样的事情(打开游戏活动时)。我的应用程序停止,并在第0行上显示了二进制XML文件错误。有点奇怪,因为我没有在第0行看到这样的问题,所以我需要大家的帮助。谢谢! 其中MainGameActivity.java:36是: activity_game_main.xml: 问题出在哪里? 问题答案: 问题出在库本身,如果您检查: 如您所见,唯一接受颜色值, 不 接受颜

  • 我已经检查了所有类似的问题(这个和其他),但仍然无法找出错误的原因,它在运行时的某个时候一直关闭。。。 ragment.java fragment\u category\u详细信息。xml 错误: 错误似乎来自这一行 我已经尽力了,非常感谢您的帮助。。。