0

I'm a beginner and completely lost trying to fix an Inflate Exception. I have a clue that the Inflate Exception is caused by the serialization of a beans class, however, how this all works together is beyond my understanding.

The logcat looks as following, note that this happens once I open a dialog containing a ListView which in turn is based on the beans class I was talking about:

01-31 12:59:22.628 27314-27314/com... I/AppCompatDelegate: The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's
01-31 12:59:22.638 27314-27314/com... D/AndroidRuntime: Shutting down VM
01-31 12:59:26.642 27314-27314/com... W/GAv4: syncDispatchLocalHits timed out: java.util.concurrent.TimeoutException
01-31 12:59:26.647 27314-27314/com... E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com..., PID: 27314
    android.view.InflateException: Binary XML file line #38: Binary XML file line #38: Error inflating class item
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com...ui.VideoPickerArrayAdapter.getView(VideoPickerArrayAdapter.java:45)
        at android.widget.AbsListView.obtainView(AbsListView.java:2346)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1281)
        at android.widget.ListView.onMeasure(ListView.java:1188)
        at android.view.View.measure(View.java:18794)
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
        at android.view.View.measure(View.java:18794)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1191)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
        at android.view.Choreographer.doFrame(Choreographer.java:606)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class item
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at com...ui.VideoPickerArrayAdapter.getView(VideoPickerArrayAdapter.java:45) 
        at android.widget.AbsListView.obtainView(AbsListView.java:2346) 
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1281) 
        at android.widget.ListView.onMeasure(ListView.java:1188) 
        at android.view.View.measure(View.java:18794) 
        at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) 
        at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) 
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) 
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) 
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) 
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) 
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) 
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) 
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) 
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:748) 
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:630) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) 
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) 
        at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643) 
        at android.view.View.measure(View.java:18794) 
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100) 
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1191) 
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452) 
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107) 
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013) 
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858) 
        at android.view.Choreographer.doCallbacks(Choreographer.java:670) 
        at android.view.Choreographer.doFrame(Choreographer.java:606) 
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.item" on path: DexPathList (...)

First of all, I have the aforementioned beans class Media.java:

public class Media implements Parcelable {
    private String duration;
    private String title;
    private URL url;
    private String contentType;
    private Bitmap thumbnail;
    private String resolution;
    private String bandwidth;

public Media(Parcel parcel) throws MalformedURLException {
    this.duration = parcel.readString();
    this.title = parcel.readString();
    this.url = new URL(parcel.readString());
    this.contentType = parcel.readString();
    this.thumbnail = parcel.readParcelable(Bitmap.class.getClassLoader());
    this.resolution = parcel.readString();
    this.bandwidth = parcel.readString();
}

/* ... */

@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(duration);
    dest.writeString(title);
    dest.writeString(url.toString());
    dest.writeString(contentType);
    dest.writeValue(thumbnail);
    dest.writeString(resolution);
    dest.writeString(bandwidth);
}

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
    public Media createFromParcel(Parcel in) {
        try {
            return new Media(in);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public Media[] newArray(int size) {
        return new Media[size];
    }
};
}

The Inflate exception occurs in this ArrayAdapter:

public class VideoPickerArrayAdapter extends ArrayAdapter<Media> {
public VideoPickerArrayAdapter(Context context, int resource, List<Media> items) {
    super(context, resource, items);
}

private class ViewHolder {
    ImageView imageView;
    TextView txtResolution;
    TextView txtDuration;
    Button btShare;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    final Media media = getItem(position);

    LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.video_picker_list_item, null);
        holder = new ViewHolder();
        holder.imageView = (ImageView) convertView.findViewById(R.id.itemicon);
        holder.txtResolution = (TextView) convertView.findViewById(R.id.itemresolution);
        holder.txtDuration = (TextView) convertView.findViewById(R.id.itemduration);
        holder.btShare = (Button) convertView.findViewById(R.id.ShareButton);
        convertView.setTag(holder);
    } else
        holder = (ViewHolder) convertView.getTag();

    holder.txtResolution.setText(media.getResolution() + "p@" + media.getBandwidth() + " Mb/s");
    holder.txtDuration.setText(media.getDurationString());
    holder.imageView.setImageBitmap(media.getThumbnail());

    /* Share button */
    holder.btShare.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(media.getUrl().toString()));
            shareIntent.setType("video/mp4");
            getContext().startActivity(Intent.createChooser(shareIntent, "Share to"));
        }
    });

    return convertView;
}

The XML layout of the listview (video_picker_list_item.xml) looks like this, note that the line 38 mentioned in the stacktrace is the Share button.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/itemicon"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:contentDescription="Videothumbnail"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/itemresolution"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingTop="8dp"
        android:paddingRight="8dp"
    />

    <TextView
        android:id="@+id/itemduration"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingRight="8dp"
        android:paddingBottom="8dp"
        android:paddingLeft="8dp"
        android:layout_below="@+id/itemresolution"
        android:textAlignment="textEnd"
        android:gravity="end"/>

    <Button
        android:id="@+id/ShareButton"
        android:title="Share"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_below="@+id/itemduration"
        android:layout_toRightOf="@+id/itemicon"
        android:layout_toEndOf="@+id/itemicon"
        android:text="Share"/>

</RelativeLayout>

Previous to making the Media class Parcelable, I would not get the Inflate exception everytime I opened the dialog, but it would still occur seemingly random like every second time I added some Media to the list and then opened the dialog. I know that the inflate exception never occured once I was able to display the list, even if I closed and opened the dialog again, unless I changed it's content. However, the App would still crash 3 seconds after I pressed the share button with an exception like 'can't marshal Media@fdsg94934'. I tried to fix this error by making the Media Parcelable, but now I'm facing the Inflate exception everytime I try to open the dialog.

I was hoping a more experienced Android developer would understand how these things work together.

Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
Zackline
  • 804
  • 1
  • 9
  • 28
  • 1
    Seems like it's related to app compatibility. Perhaps this SO question will help http://stackoverflow.com/questions/31677552/the-activitys-layoutinflater-already-has-a-factory-installed-so-we-can-not-inst. Possibly your call to getContext() in your click listener needs to be a call to getSupportActionBar().getThemedContext()? Stepping through with a debugger should shed some light on where you're blowing up exactly. – JJF Jan 31 '16 at 14:14
  • @JJF Thank you! I read the same question earlier today, but dismissed it. After switching to the themed context, the factory already installed error persists, however, the inflation exception is gone. The style of the share button has changed to black and all textviews seem to be invisible. But I'm glad the error was fixed. A bit offtopic, but is it just me or is the API overcomplicated at times? I mean, how am I supposed to relate an inflation error dependent on the serialization of another class to the themed context of an ActionBar not even related in any way to the dialog? – Zackline Jan 31 '16 at 18:19

0 Answers0