仅在4.4设备中出现了奇怪的InflateException

时间:2019-01-05 12:37:36

标签: android android-layout inflate-exception

首先,请先阅读问题,然后再将其标记为重复。我仅在棒棒糖之前的android版本中才在自己的android应用程序中获取InflateException。我的设备和所有其他模拟器都可以正常运行。代码仍然正确,我正在获取InflateException,即运行时。这是我从控制台获得的堆栈跟踪:

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2429)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2493)
  at android.app.ActivityThread.access$800 (ActivityThread.java:166)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1283)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:136)
  at android.app.ActivityThread.main (ActivityThread.java:5584)
  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:1268)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1084)
  at dalvik.system.NativeStart.main (Native Method)
Caused by: android.view.InflateException: 
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:720)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:762)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:771)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:771)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:771)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:499)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:398)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:354)
  at android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
  at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
  at com.neupanedinesh.coolcaptions.SearchActivity.onCreate (SearchActivity.java:39)
  at android.app.Activity.performCreate (Activity.java:5447)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1094)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2393)
Caused by: android.content.res.Resources$NotFoundException: 
  at android.content.res.Resources.loadDrawable (Resources.java:3451)
  at android.content.res.TypedArray.getDrawable (TypedArray.java:614)
  at android.widget.ImageView.<init> (ImageView.java:134)
  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:71)
  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:67)
  at android.support.v7.app.AppCompatViewInflater.createImageView (AppCompatViewInflater.java:181)
  at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:105)
  at android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1035)
  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1092)
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:691)
Caused by: org.xmlpull.v1.XmlPullParserException: 
  at android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:969)
  at android.graphics.drawable.Drawable.createFromXml (Drawable.java:913)
  at android.content.res.Resources.loadDrawable (Resources.java:3447)

这是来自播放控制台的日志。 这是我的SearchActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        toolbar=findViewById(R.id.fab_toolbar);
        setSupportActionBar(toolbar);

       iv=findViewById(R.id.search_empty);
        createExampleList();
        buildRecyclerView();

        final EditText editText = findViewById(R.id.searchText);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(count>0){
                    iv.setVisibility(View.GONE);
                    mRecyclerView.setVisibility(View.VISIBLE);
                }else {
                    mRecyclerView.setVisibility(View.GONE);
                    iv.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
                filter(s.toString());
            }
        });
        ImageView clearText=findViewById(R.id.clearText);
        clearText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editText.getText().clear();
            }
        });
    }

有人可以帮助我弄清楚实际上是什么导致了错误吗? (来自Android 4.4的错误的100%)

这是我要膨胀的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/cg"
    android:orientation="vertical"
    tools:context=".SearchActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/fab_appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/fab_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@color/primary"
            android:elevation="@dimen/toolbar_elevation">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/backButton"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="-10dp"
                    android:layout_weight="0.20"
                    android:src="@drawable/abc_ic_ab_back_material" />

                <EditText
                    android:id="@+id/searchText"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.70"
                    android:background="@android:color/transparent"
                    android:hint="Type a keyword.."
                    android:textColorHint="#bec4c2"
                    android:textCursorDrawable="@null" />

                <ImageView
                    android:id="@+id/clearText"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="-40dp"
                    android:layout_weight="0.15"
                    android:src="@drawable/close" />

            </LinearLayout>
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>


    <ImageView
        android:id="@+id/search_empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="140dp"
        android:src="@drawable/search_small" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" />


</LinearLayout>

1 个答案:

答案 0 :(得分:0)

根据崩溃日志,找不到可绘制对象:android.content.res.Resources$NotFoundException: at android.content.res.Resources.loadDrawable

我真的不能说出布局文件中哪个引用的可绘制对象引起了问题。因此,请尝试先将其全部删除,然后启动您的应用。如果它没有崩溃,则将可绘制对象一个接一个地添加回布局中,以查看找不到哪个可绘制对象。