Error inflating class ImageView

前端 未结 17 2218
失恋的感觉
失恋的感觉 2020-12-29 21:01

I\'ve been getting InflateException/ClassNotFoundException error intermittently. I\'ve seen similar errors before in SO but they were caused by spelling errors. I spelled \'

相关标签:
17条回答
  • 2020-12-29 21:46

    For me, inside one of my layout.xml files, I had

    <ImageView
        android:id="@+id/row_1_col_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@string/default_picture_location">
    </ImageView>
    

    and inside strings.xml, I had

    <string name="default_picture_location">"@mipmap/tile"</string>
    

    and so it was showing this in Android Studio:

    <ImageView
        android:id="@+id/row_1_col_0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@mipmap/tile">
    </ImageView>
    

    I thought everything would work because there were no errors and the application compiled and ran. However, there was a run time error that said "android.view.InflateException: Binary XML file line #7:Error inflating class ImageView".

    Once I changed android:background from

    android:background="@string/default_picture_location"
    

    to

    android:background="@mipmap/tile"
    

    everything worked.

    0 讨论(0)
  • 2020-12-29 21:47

    For me it works when I paste image in both drawable and drawable-v24 and I added some code android:src="@drawable/battman"

    0 讨论(0)
  • 2020-12-29 21:53

    try to change

    v = View.inflate(getContext(), R.layout.event_show_row_layout, null);
    

    to

    v = View.inflate(getApplicationContext(), R.layout.event_show_row_layout, null);
    
    0 讨论(0)
  • 2020-12-29 21:56

    Putting image in drawable NOT as "v-24" worked for me and I stopped get the crash.

    0 讨论(0)
  • 2020-12-29 21:56

    you haven't closed LinearLayout tag

    and please use following code for inflating layout.xml

    LayoutInflater inflater = getLayoutInflater();
    final View v = inflater.inflate(R.layout.your_layout_id, null);
    
    0 讨论(0)
  • 2020-12-29 21:58

    I have the resources in the drawable-zh-xxhdpi catalog documents, but not in the drawable-xxhdpi catalog of resources, the emergence of this mistake.

    This should be:

    res
      drawable-xxhdpi
         aa.png
      drawable-zh-xxhdpi
         aa.png
    
    0 讨论(0)
提交回复
热议问题