-1

First of all please read the question before marking as duplicate. I am getting InflateException in one of my android app only in android versions earlier than lollipop. Works fine with my devices and all other simulators.The code there is just right still I'm getting InflateException and that is Runtime. Here is my stack trace from console:

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)

It's the log from play console. And here is my 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();
            }
        });
    }

Can anybody help me figure out what actually is causing error? (100% of the error from Android 4.4)

Here is my xml that I'm trying to inflate:

<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>
Sopnil Shah
  • 51
  • 2
  • 7

1 Answers1

0

According to the crash log, a drawable can't be found: android.content.res.Resources$NotFoundException: at android.content.res.Resources.loadDrawable

I can't really tell which of the referenced drawables in your layout file causes the problem. So try removing all of them first and launch your app. If it doesn't crash, add your drawables back into the layout one by one to see which of them can't be found.

Alexander Hoffmann
  • 5,104
  • 3
  • 17
  • 23
  • it's happening only in pre lollipop devices, and i don't think background drawable for root layout is the cause because it's happening only in this activity, other activities with same exact drawable as background are working just fine. very hard to figure where its going wrong. – Sopnil Shah Jan 07 '19 at 16:12
  • But you still have other drawables, not only the background drawable. e.g. `android:src="@drawable/abc_ic_ab_back_material"` and many more. – Alexander Hoffmann Jan 07 '19 at 20:06