35

我间歇性地收到 InflateException/ClassNotFoundException 错误。我以前在 SO 中看到过类似的错误,但它们是由拼写错误引起的。我正确拼写了“ImageView”,所以我不知道是什么导致了错误。

发生错误的代码是:

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

这是布局xml:

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

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="10dip"
        android:paddingRight="10dip" >

        <TextView
            android:id="@+id/fromTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/timeTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textSize="12sp"
            android:textStyle="italic" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutPostImage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="4dp" >

        <ImageView
            android:id="@+id/postImageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_margin="2dp"
            android:adjustViewBounds="true"
            android:background="@drawable/timeline_image_border"
            android:contentDescription="@string/hello"
            android:paddingBottom="6dp"
            android:scaleType="fitXY"
            android:src="@drawable/timeline_image_dummy" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/wordsRelativeLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/wordsTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical|center_horizontal"
            android:paddingLeft="50dp"
            android:paddingRight="50dp"
            android:text="@string/hello" />

        <ImageView
            android:id="@+id/topLeftQuoteImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello"
            android:maxHeight="25dp"
            android:maxWidth="25dp"
            android:scaleType="fitXY"
            android:src="@drawable/po_quotes_mobile1" />

        <ImageView
            android:id="@+id/bottomRightQuoteImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="12dp"
            android:layout_marginRight="12dp"
            android:adjustViewBounds="true"
            android:contentDescription="@string/hello"
            android:maxHeight="25dp"
            android:maxWidth="25dp"
            android:scaleType="fitXY"
            android:src="@drawable/po_quotes_mobile2" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:id="@+id/commentButton"
            android:layout_width="84dp"
            android:layout_height="24dp"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="5dp"
            android:background="@drawable/es_comment_btn" />

        <Button
            android:id="@+id/buttonLike"
            android:layout_width="84dp"
            android:layout_height="24dp"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/commentButton"
            android:background="@drawable/es_like_btn" />

        <Button
            android:id="@+id/buttonNumberLike"
            android:layout_width="wrap_content"
            android:layout_height="24dp"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/buttonLike"
            android:background="@drawable/like_counter"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/buttonDelete"
            android:layout_width="38dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_marginRight="5dp"
            android:background="@drawable/es_more_btn" />
    </RelativeLayout>

    <TextView
        android:id="@+id/commentsTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:background="#FFF9F8F1"
        android:text="@string/hello"
        android:textColor="@android:color/black"
        android:textSize="12sp" />

    <TextView
        android:id="@+id/spacerTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp" />

</LinearLayout>

这是错误日志:

E/AndroidRuntime(15849): FATAL EXCEPTION: main
E/AndroidRuntime(15849): android.view.InflateException: Binary XML file line #36: Error inflating class ImageView
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:454)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:737)
E/AndroidRuntime(15849):    at  org.holoeverywhere.LayoutInflater.rInflate(LayoutInflater.java:740)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:542)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:492)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.inflate(LayoutInflater.java:487)
E/AndroidRuntime(15849):    at android.view.View.inflate(View.java:8807)
E/AndroidRuntime(15849):    at com.mypackage.adapters.PostAdapter.getPostView(PostAdapter.java:283)
E/AndroidRuntime(15849):    at com.mypackage.adapters.PostAdapter.getView(PostAdapter.java:268)
E/AndroidRuntime(15849):    at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
E/AndroidRuntime(15849):    at android.widget.AbsListView.obtainView(AbsListView.java:1430)
E/AndroidRuntime(15849):    at android.widget.ListView.makeAndAddView(ListView.java:1745)
E/AndroidRuntime(15849):    at android.widget.ListView.fillDown(ListView.java:670)
E/AndroidRuntime(15849):    at android.widget.ListView.fillFromTop(ListView.java:727)
E/AndroidRuntime(15849):    at android.widget.ListView.layoutChildren(ListView.java:1598)
E/AndroidRuntime(15849):    at android.widget.AbsListView.onLayout(AbsListView.java:1260)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at net.simonvt.menudrawer.LeftDrawer.onLayout(LeftDrawer.java:64)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(15849):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(15849):    at android.view.View.layout(View.java:7175)
E/AndroidRuntime(15849):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
E/AndroidRuntime(15849):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
E/AndroidRuntime(15849):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(15849):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(15849):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(15849):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(15849):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(15849):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(15849):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(15849):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(15849): Caused by: java.lang.ClassNotFoundException: Could not find class: ImageView
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.onCreateView(LayoutInflater.java:607)
E/AndroidRuntime(15849):    at org.holoeverywhere.LayoutInflater.createViewFromTag(LayoutInflater.java:448)
E/AndroidRuntime(15849):    ... 48 more
4

18 回答 18

74

我有同样的问题。我的问题发生了,因为我刚刚在“drawable-v24”文件夹中使用了图像(图标)。我通过将它们复制到“可绘制”文件夹中来解决它

于 2018-05-16T20:40:26.503 回答
18

我最近遇到了同样的问题,并且能够使用app:srcCompat="@drawable/ic_black_image_24"

国家的文件appcompat:srcCompat-

它将一个可绘制对象设置为此 ImageView 的内容。在旧版本的平台上运行时允许使用矢量可绘制对象。

如果有人偶然发现同样的问题,希望这会有所帮助。

于 2017-08-28T10:52:05.577 回答
10

对我来说,我将我的图像复制到文件夹drawable-v24并且编译器没有找到它

将 Android Studio 的视图更改为项目视图

项目视图

并将图像剪切并粘贴到文件夹drawable

于 2018-08-17T18:01:55.467 回答
8

我遇到了同样的问题,因为我在 Android 视图上将我的 png 文件复制到 drawables,它会自动复制到 drawable-v24,但是您需要将文件复制到 drawable,您可以导航到您的项目然后 res/drawables 和手动粘贴它,或将视图更改为项目视图,将其放在可绘制文件夹中

于 2020-04-24T17:05:27.433 回答
7

我自己也有这个问题,因为我的图像在 darawable-v24 目录中。所以当我想使用旧的 api 时,应用程序崩溃了。所以我建议检查你的资源是否在正确的目录中。

https://stacklearn.ir

于 2019-02-24T09:04:32.260 回答
5

尝试改变

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

v = View.inflate(getApplicationContext(), R.layout.event_show_row_layout, null);
于 2013-07-29T12:14:36.223 回答
5

这是一个老问题,但我刚刚遇到了同样的问题。在我的情况下,它是由使用android:tint带有 aselector而不是 a的属性引起的color

<ImageView
    ...
    android:tint="@drawable/some_selector" />

虽然这可以毫无问题地使用 SDK 21+,但它在旧版本中会崩溃......

切换到AppCompatImageViewapp:tint解决问题:

<android.support.v7.widget.AppCompatImageView
    ...
    app:tint="@drawable/some_selector" />
于 2018-04-27T08:01:59.837 回答
4

对我来说,在我的一个 layout.xml 文件中,我有

<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>

在strings.xml里面,我有

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

所以它在 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>

我认为一切都会正常工作,因为没有错误并且应用程序已编译并运行。但是,有一个运行时错误说“android.view.InflateException:二进制 XML 文件行 #7:错误膨胀类 ImageView”。

一旦我改变了 android:background 从

android:background="@string/default_picture_location"

android:background="@mipmap/tile"

一切正常。

于 2015-10-30T01:05:47.737 回答
3

将图像放入可绘制而不是“v-24”对我有用,我停止了崩溃。

于 2018-12-04T11:17:51.490 回答
3

我的drawable-zh-xxhdpi目录中有资源文件,但是资源目录中没有drawable-xxhdpi,出现这个错误。

这应该是:</p>

res
  drawable-xxhdpi
     aa.png
  drawable-zh-xxhdpi
     aa.png
于 2017-02-14T10:23:55.140 回答
2

不要将 XML 文件和图像文件命名为相同的名称,如下所示:

在此处输入图像描述

于 2019-05-21T03:35:16.000 回答
2

膨胀过程中的错误可能来自 ImageView 中使用的 drawable,在这种情况下:

android:background="@drawable/timeline_image_border"
android:src="@drawable/timeline_image_dummy"

要摆脱它,请替换所有现有图像,尝试使用不同的可绘制对象。

于 2016-10-07T10:30:45.377 回答
1

你还没有关闭 LinearLayout 标签

并请使用以下代码膨胀 layout.xml

LayoutInflater inflater = getLayoutInflater();
final View v = inflater.inflate(R.layout.your_layout_id, null);
于 2013-07-29T12:06:05.540 回答
1

就我而言,我遇到了同样的错误,但在使用 API < 24 的设备(模拟器或物理设备)时。

这是由于在我导入的 SVG 中使用“渐变”引起的。

错误不会出现在堆栈跟踪中,但会出现在导入的 SVG 文件的 .xml 中:

在此处输入图像描述

对于 API < 24,这会导致应用程序在对以此 SVG 作为其源的 View 进行膨胀时崩溃。

如果您只想使用 SVG,您可以将此资源的使用限制为 API >= 24,并删除以下 API 的渐变。

于 2017-11-22T09:53:10.560 回答
1

对我来说,当我在两者中粘贴图像drawabledrawable-v24添加一些代码时它就可以工作android:src="@drawable/battman"

于 2019-02-21T22:16:48.557 回答
0

在我的情况下,svg 的字母有间隙,然后这导致了这个错误,我所做的就是修改 illustrator 中的字母以消除间隙并且它起作用了。

于 2020-06-10T02:43:30.927 回答
0

就我而言,它是具有长路径的 SVG 图像。它显示错误:

原因:java.lang.IllegalArgumentException:R 不是有效动词。路径的位置 2 发生故障:STRING_TOO_LARGE

查看长 SVG 资产文件错误:R 不是有效动词。路径的位置 2 发生故障:STRING_TOO_LARGEpath将 s 拆分为几个低于 32Kb 的大小。

于 2021-02-02T13:15:17.267 回答
0

对我来说,问题是 svg 文件太大了。

于 2020-04-04T17:07:17.310 回答