代码之家  ›  专栏  ›  技术社区  ›  Pouya Danesh

如何处理android.view.inflateexception二进制XML文件行#5

  •  1
  • Pouya Danesh  · 技术社区  · 11 年前

    所以我在发展,我遇到了一个交叉膨胀的例外,我不知道该怎么办。

    日志目录:

    03-09 16:33:12.018    8201-8201/org.aron.modiryar E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: org.aron.modiryar, PID: 8201
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.aron.modiryar/org.aron.modiryar.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:212)
            at android.app.ActivityThread.main(ActivityThread.java:5135)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:620)
            at `com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at org.aron.modiryar.fragment.MainMenu.onCreateView(MainMenu.java:41)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at       android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
            at     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
            at android.app.Activity.performStart(Activity.java:5241)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
      Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    

    这是我的机器人 显示:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.aron.modiryar"
    android:versionCode="1"
    android:versionName="1.0" android:uiOptions="splitActionBarWhenNarrow">
    
    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="14" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    <application
        android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name"
        android:theme="@style/AppBaseTheme" android:enabled="true" android:name=".system.Initialize"
        android:uiOptions="splitActionBarWhenNarrow">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden"
            android:uiOptions="splitActionBarWhenNarrow" >
            <meta-data android:name="android.support.UI_OPTIONS"
                       android:value="splitActionBarWhenNarrow" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    </manifest>
    

    我的布局是这样的:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/mainmenulayer" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" android:visibility="visible"  style="@style/MainMenu">
       <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
        <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_title_height" android:orientation="horizontal" style="@style/RowMenu">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_title_collect" style="@style/RowMenuTitleText" />
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_inbox">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount" android:orientation="horizontal"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible" android:orientation="horizontal"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:id="@+id/menu_inbox_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_inbox" style="@style/RowMenuText" />
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_inbox"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_title_height" android:orientation="horizontal" style="@style/RowMenu">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_title_focuse_on" style="@style/RowMenuTitleText" />
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_today">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_today" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_today"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_next_action">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_next_action" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_next"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_tomorrow">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_tomorrow" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_tomorrow"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_calendar">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_calendar" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_scheduled"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_someday">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_sameday" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_someday"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_waitingfor">
                <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginLeft="@dimen/main_menu_row_count_margin_left">
                    <LinearLayout android:id="@+id/total_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/TotalCount"></LinearLayout>
                    <LinearLayout android:id="@+id/overdue_count" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/OverDueCount" android:visibility="invisible"></LinearLayout>
                </LinearLayout>
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_waitingfor" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_waiting"/>
            </LinearLayout>
    
            <LinearLayout android:layout_width="fill_parent" android:layout_height="@dimen/main_menu_divider_line_height" style="@style/MainMenuLine"/>
            <LinearLayout android:layout_width="fill_parent" android:layout_height="@dimen/main_menu_divider_line_height" style="@style/MainMenuLineWhite"/>
    
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_project">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_project" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_project"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_Goal">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_goal" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_goal"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_responsibility">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_responsibility" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_responsibility"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_vision">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_vision" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_inbox"/>
            </LinearLayout>
    
            <LinearLayout android:layout_width="fill_parent" android:layout_height="@dimen/main_menu_divider_line_height" style="@style/MainMenuLine"/>
            <LinearLayout android:layout_width="fill_parent" android:layout_height="@dimen/main_menu_divider_line_height" style="@style/MainMenuLineWhite"/>
    
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_reference">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_reference" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_inbox"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_trash">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_trash" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_trash"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_done">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_done" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_trash"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_routine">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_routine" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_inbox"/>
            </LinearLayout>
            <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/main_menu_row_height" android:orientation="horizontal" style="@style/RowMenu" android:id="@+id/menu_tags">
                <org.aron.modiryar.view.TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/menu_tags" style="@style/RowMenuText"/>
                <ImageView android:layout_width="@dimen/main_menu_row_icon_width" android:layout_height="@dimen/main_menu_row_icon_height" android:src="@drawable/home_tags"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
    

    正如你可能看到或没有看到的 linearlayouts 有相同的ID,但我知道这不是我的问题。 真正的问题是应用程序在早期的android版本上运行,而不是在更高版本上运行。 我已经尝试在android清单中更改目标sdk。

    所以我错过了什么,请帮忙。

    public class TextView extends android.widget.TextView {
    public TextView(Context context) {
        super(context);
        this.setTypeface(Config.getDefaultTypeFace(context));
    }
    
    public TextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setTypeface(Config.getDefaultTypeFace(context));
    }
    
    public TextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.setTypeface(Config.getDefaultTypeFace(context));
    }
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Pouya Danesh    10 年前

    因此,经过大约8个小时的努力,我发现了我的问题所在,我正在发布这个答案,这样可以帮助其他人。

    1-正如你在堆栈跟踪中看到的那样,我的问题是在MainMenu.java中膨胀,所以我的问题在于膨胀的布局。

    2-XML文件第5行位于该布局中。它可能看起来很无辜,但它有一种风格。

    在这种风格中,它的维度只有在大的值中定义,这是我的问题。我必须在所有其他维度值中定义它才能工作。

    注意:我的问题不在SDK版本中,而是在设备大小上。 希望这对其他人有所帮助。