Android - 错误膨胀文本视图

时间:2017-03-05 04:17:06

标签: android android-layout android-fragments

我知道stackoverflow上有很多类似的问题。 但这些都没有解决我的问题。

它与主题设置无关,也未找到资源。 而且我没有在这个布局中加载大图像(所有背景都来自可绘制的xml)。 所有属性都具有准确的值,包括名称空间声明。 它只是随机抛出这个异常。 看起来像一个机器人的bug。

它发生在Nexus 5X,Nexus 6P,HTC_A9u,ASUS_Z012等。 我使用的是API 25,支持库25.0.1,构建工具25.0.2。

我在更改为使用API​​ 25后开始报告此异常。

布局中有20个类似的节点,ScrollView。 并且Fragment拥有此布局。 我用片段事务初始化它,然后把它放在DrawerLayout

布局节点:

<ScrollView
    android:id="@+id/mainMenuScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        ...

        <RelativeLayout
            android:id="@+id/aboutHolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:paddingTop="7dp"
            android:paddingBottom="7dp"
            android:paddingStart="10dp"
            android:paddingEnd="5dp"
            android:clickable="true"
            android:background="?theme.mainMenuItemBackground"
            android:layout_below="@+id/otherHolder">
            <TextView
                    android:id="@+id/aboutCapital"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_centerVertical="true"
                    android:background="@drawable/my_background"
                    android:gravity="center"
                    android:textSize="14sp"
                    android:textColor="?theme.titleColor"
                    android:text="A"/>
            <TextView
                    android:id="@+id/aboutName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="10dp"
                    android:layout_toEndOf="@+id/aboutCapital"
                    android:textStyle="bold"
                    android:textSize="@dimen/menu_item_title"
                    android:textColor="?theme.titleColor"
                    android:text="About"/>
        </RelativeLayout>

        ...

    </RelativeLayout>

</ScrollView>

它也发生在ScrollView或类似<unknown>

错误日志(TextView):

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.LauncherActivity}: android.view.InflateException: Binary XML file line #813: Binary XML file line #813: Error inflating class TextView
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2665)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

Caused by android.view.InflateException: Binary XML file line #813: Binary XML file line #813: Error inflating class TextView

Caused by android.view.InflateException: Binary XML file line #813: Error inflating class TextView

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference
android.content.res.AssetManager.getPooledStringForCookie (AssetManager.java:306)
android.content.res.TypedArray.loadStringValueAt (TypedArray.java:1217)
android.content.res.TypedArray.getValueAt (TypedArray.java:1203)
android.content.res.TypedArray.getColorStateList (TypedArray.java:526)
android.widget.TextView.<init> (TextView.java:1080)
android.widget.TextView.<init> (TextView.java:704)
android.support.v7.widget.AppCompatTextView.<init> (AppCompatTextView.java:62)
android.support.v7.widget.AppCompatTextView.<init> (AppCompatTextView.java:58)
android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:103)
android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1017)
android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1076)
android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView (LayoutInflaterCompatHC.java:44)
android.view.LayoutInflater$FactoryMerger.onCreateView (LayoutInflater.java:192)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:769)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
com.example.myapp.MainMenuFragment.onCreateView (MainMenuFragment.java:306)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2087)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1113)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1295)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1277)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManagerImpl.java:2154)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:181)
com.example.myapp.LauncherActivity.onStart (LauncherActivity.java:2193)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
android.app.Activity.performStart (Activity.java:6696)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2628)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

错误日志(<unknown>

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.LauncherActivity}: android.view.InflateException: Binary XML file line #1051: Binary XML file line #1051: Error inflating class <unknown>
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2666)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2727)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1478)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6121)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:876)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:766)

Caused by android.view.InflateException: Binary XML file line #1051: Binary XML file line #1051: Error inflating class <unknown>

Caused by android.view.InflateException: Binary XML file line #1051: Error inflating class <unknown>

Caused by java.lang.reflect.InvocationTargetException:
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:430)
android.view.LayoutInflater.createView (LayoutInflater.java:645)
com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
android.view.LayoutInflater.onCreateView (LayoutInflater.java:717)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:785)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
com.example.myapp.MainMenuFragment.onCreateView (MainMenuFragment.java:306)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2087)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1113)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1295)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1277)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManagerImpl.java:2154)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:181)
com.example.myapp.LauncherActivity.onStart (LauncherActivity.java:2193)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
android.app.Activity.performStart (Activity.java:6699)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2629)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2727)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1478)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6121)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:876)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:766)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference
android.content.res.AssetManager.getPooledStringForCookie (AssetManager.java:306)
android.content.res.TypedArray.loadStringValueAt (TypedArray.java:1217)
android.content.res.TypedArray.getValueAt (TypedArray.java:1203)
android.content.res.TypedArray.getDrawable (TypedArray.java:923)
android.view.View.<init> (View.java:4202)
android.view.ViewGroup.<init> (ViewGroup.java:579)
android.widget.RelativeLayout.<init> (RelativeLayout.java:248)
android.widget.RelativeLayout.<init> (RelativeLayout.java:244)
android.widget.RelativeLayout.<init> (RelativeLayout.java:240)
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:430)
android.view.LayoutInflater.createView (LayoutInflater.java:645)
com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
android.view.LayoutInflater.onCreateView (LayoutInflater.java:717)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:785)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
com.example.myapp.MainMenuFragment.onCreateView (MainMenuFragment.java:306)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2087)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1113)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1295)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1277)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManagerImpl.java:2154)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:181)
com.example.myapp.LauncherActivity.onStart (LauncherActivity.java:2193)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
android.app.Activity.performStart (Activity.java:6699)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2629)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2727)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1478)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6121)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:876)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:766)

错误日志(ScrollView):

Exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.LauncherActivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class android.widget.ScrollView
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2665)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

Caused by android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class android.widget.ScrollView

Caused by android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.ScrollView

Caused by java.lang.reflect.InvocationTargetException:
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:430)
android.view.LayoutInflater.createView (LayoutInflater.java:645)
com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
android.view.LayoutInflater.onCreateView (LayoutInflater.java:717)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:785)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
com.example.myapp.MainMenuFragment.onCreateView (MainMenuFragment.java:288)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2087)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1113)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1295)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1277)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManagerImpl.java:2154)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:181)
com.example.myapp.LauncherActivity.onStart (LauncherActivity.java:2196)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
android.app.Activity.performStart (Activity.java:6696)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2628)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference
android.content.res.AssetManager.getPooledStringForCookie (AssetManager.java:306)
android.content.res.TypedArray.loadStringValueAt (TypedArray.java:1217)
android.content.res.TypedArray.getValueAt (TypedArray.java:1203)
android.content.res.TypedArray.getDrawable (TypedArray.java:923)
android.view.View.initializeScrollbarsInternal (View.java:5133)
android.view.View.<init> (View.java:4660)
android.view.ViewGroup.<init> (ViewGroup.java:579)
android.widget.FrameLayout.<init> (FrameLayout.java:92)
android.widget.ScrollView.<init> (ScrollView.java:180)
android.widget.ScrollView.<init> (ScrollView.java:176)
android.widget.ScrollView.<init> (ScrollView.java:172)
java.lang.reflect.Constructor.newInstance0 (Constructor.java)
java.lang.reflect.Constructor.newInstance (Constructor.java:430)
android.view.LayoutInflater.createView (LayoutInflater.java:645)
com.android.internal.policy.PhoneLayoutInflater.onCreateView (PhoneLayoutInflater.java:58)
android.view.LayoutInflater.onCreateView (LayoutInflater.java:717)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:785)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
com.example.myapp.MainMenuFragment.onCreateView (MainMenuFragment.java:288)
android.support.v4.app.Fragment.performCreateView (Fragment.java:2087)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1113)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1295)
android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1277)
android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated (FragmentManagerImpl.java:2154)
android.support.v4.app.FragmentController.dispatchActivityCreated (FragmentController.java:201)
android.support.v4.app.FragmentActivity.onStart (FragmentActivity.java:603)
android.support.v7.app.AppCompatActivity.onStart (AppCompatActivity.java:181)
com.example.myapp.LauncherActivity.onStart (LauncherActivity.java:2196)
android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1248)
android.app.Activity.performStart (Activity.java:6696)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2628)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2726)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6119)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)

1 个答案:

答案 0 :(得分:0)

我认为你的问题是:

android:textColor="?theme.titleColor"

你应该改为@color/yourcolor或十六进制颜色