android.view.InflateException:二进制 XML 文件第 12 行:错误膨胀类<未知>;

发布于 2024-10-08 17:40:16 字数 7465 浏览 3 评论 0 原文

我收到主题中显示的许多此类错误。这些错误似乎是偶然的,我无法重现它们。从堆栈中我可以了解到,我的不同布局资源可能会发生此类错误。 XML 的行也各不相同。

谁能解释为什么会出现这个错误?我能做些什么来解决这个问题?

Stack

=============================================================

com.fsp.android.f generated the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fsp.android.f/com.life360.android.ui.tour.TourActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

--------- Stack trace ---------
1. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
2. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
3. android.app.ActivityThread.access$2200(ActivityThread.java:131)
4. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
5. android.os.Handler.dispatchMessage(Handler.java:99)
6. android.os.Looper.loop(Looper.java:123)
7. android.app.ActivityThread.main(ActivityThread.java:4702)
8. java.lang.reflect.Method.invokeNative(Native Method)
9. java.lang.reflect.Method.invoke(Method.java:521)
10. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12. dalvik.system.NativeStart.main(Native Method)
-------------------------------

----------- Cause -----------
android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

1. android.view.LayoutInflater.createView(LayoutInflater.java:513)
2. com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
3. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
4. android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
5. android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
6. android.view.LayoutInflater.inflate(LayoutInflater.java:382)
7. android.view.LayoutInflater.inflate(LayoutInflater.java:320)
8. android.view.LayoutInflater.inflate(LayoutInflater.java:276)
9. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
10. android.app.Activity.setContentView(Activity.java:1629)
11. com.solvek.sample.ui.BaseActivity.onCreate(BaseActivity.java:23)
12. com.solvek.sample.ui.tour.TourActivity.onCreate(TourActivity.java:161)
13. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
14. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
15. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
16. android.app.ActivityThread.access$2200(ActivityThread.java:131)
17. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
18. android.os.Handler.dispatchMessage(Handler.java:99)
19. android.os.Looper.loop(Looper.java:123)
20. android.app.ActivityThread.main(ActivityThread.java:4702)
21. java.lang.reflect.Method.invokeNative(Native Method)
22. java.lang.reflect.Method.invoke(Method.java:521)
23. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
24. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
25. dalvik.system.NativeStart.main(Native Method)
-----------------------------

-------- Environment --------
Time =2010-12-20 08:27:35 AM
Device =tmobile/htc_espresso/espresso/espresso:2.1-update1/ERE27/216830:user/release-keys
Make =HTC
Model =T-Mobile myTouch 3G Slide
Product =htc_espresso
App =com.fsp.android.f, version 2.0.9 (build 1232)

这里是XML的结果,但是在其他xml中也会出现这样的错误

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ViewFlipper android:layout_gravity="fill" android:id="@+id/flipper" android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_1"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_2"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_3"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_4"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_5"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_6"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_7"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_8"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_9"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_10"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_11"/>
    </ViewFlipper>

    <LinearLayout android:id="@+id/exit_bar" android:layout_gravity="top" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <Button android:background="@drawable/orange_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:textStyle="bold" android:textColor="#000000" android:shadowColor="#ffffff" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:id="@+id/exit_tour_btn" android:text="Exit" android:layout_marginLeft="20dip"/>
        <TextView android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_gravity="center" android:layout_width="110dip" android:layout_marginLeft="20dip" android:textSize="16dip" android:textStyle="bold" android:text="Life360 Tour"/>

    </LinearLayout>

    <Button style="@style/BlueBtn" android:text="Continue" android:layout_marginTop="40dip" android:id="@+id/continue_btn" android:visibility="gone" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" />

    <FrameLayout android:id="@+id/bottom_bar" android:layout_gravity="bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/left" android:layout_gravity="left|center" android:background="@drawable/tour_left" android:layout_marginLeft="10dip"/>
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/right" android:layout_gravity="right|center" android:background="@drawable/tour_right" android:layout_marginRight="10dip"/>               
    </FrameLayout>
</merge>

I am receiving many errors of kind displayed in the subj. These errors seems to be occasional and I cannot reproduce them. From stack I can learn that such error may occurs for my different layout resources. The line of XML is also varying.

Can anybody explain why this error occurs? And what I can do to fix this problem?

Stack

=============================================================

com.fsp.android.f generated the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fsp.android.f/com.life360.android.ui.tour.TourActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

--------- Stack trace ---------
1. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
2. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
3. android.app.ActivityThread.access$2200(ActivityThread.java:131)
4. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
5. android.os.Handler.dispatchMessage(Handler.java:99)
6. android.os.Looper.loop(Looper.java:123)
7. android.app.ActivityThread.main(ActivityThread.java:4702)
8. java.lang.reflect.Method.invokeNative(Native Method)
9. java.lang.reflect.Method.invoke(Method.java:521)
10. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12. dalvik.system.NativeStart.main(Native Method)
-------------------------------

----------- Cause -----------
android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

1. android.view.LayoutInflater.createView(LayoutInflater.java:513)
2. com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
3. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
4. android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
5. android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
6. android.view.LayoutInflater.inflate(LayoutInflater.java:382)
7. android.view.LayoutInflater.inflate(LayoutInflater.java:320)
8. android.view.LayoutInflater.inflate(LayoutInflater.java:276)
9. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
10. android.app.Activity.setContentView(Activity.java:1629)
11. com.solvek.sample.ui.BaseActivity.onCreate(BaseActivity.java:23)
12. com.solvek.sample.ui.tour.TourActivity.onCreate(TourActivity.java:161)
13. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
14. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
15. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
16. android.app.ActivityThread.access$2200(ActivityThread.java:131)
17. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
18. android.os.Handler.dispatchMessage(Handler.java:99)
19. android.os.Looper.loop(Looper.java:123)
20. android.app.ActivityThread.main(ActivityThread.java:4702)
21. java.lang.reflect.Method.invokeNative(Native Method)
22. java.lang.reflect.Method.invoke(Method.java:521)
23. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
24. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
25. dalvik.system.NativeStart.main(Native Method)
-----------------------------

-------- Environment --------
Time =2010-12-20 08:27:35 AM
Device =tmobile/htc_espresso/espresso/espresso:2.1-update1/ERE27/216830:user/release-keys
Make =HTC
Model =T-Mobile myTouch 3G Slide
Product =htc_espresso
App =com.fsp.android.f, version 2.0.9 (build 1232)

Here is a result of XML, however such error occurs in other xmls

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ViewFlipper android:layout_gravity="fill" android:id="@+id/flipper" android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_1"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_2"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_3"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_4"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_5"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_6"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_7"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_8"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_9"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_10"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_11"/>
    </ViewFlipper>

    <LinearLayout android:id="@+id/exit_bar" android:layout_gravity="top" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <Button android:background="@drawable/orange_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:textStyle="bold" android:textColor="#000000" android:shadowColor="#ffffff" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:id="@+id/exit_tour_btn" android:text="Exit" android:layout_marginLeft="20dip"/>
        <TextView android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_gravity="center" android:layout_width="110dip" android:layout_marginLeft="20dip" android:textSize="16dip" android:textStyle="bold" android:text="Life360 Tour"/>

    </LinearLayout>

    <Button style="@style/BlueBtn" android:text="Continue" android:layout_marginTop="40dip" android:id="@+id/continue_btn" android:visibility="gone" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" />

    <FrameLayout android:id="@+id/bottom_bar" android:layout_gravity="bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/left" android:layout_gravity="left|center" android:background="@drawable/tour_left" android:layout_marginLeft="10dip"/>
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/right" android:layout_gravity="right|center" android:background="@drawable/tour_right" android:layout_marginRight="10dip"/>               
    </FrameLayout>
</merge>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

情归归情 2024-10-15 17:40:16

Inflate 异常实际上并不是问题,而是来自布局中的另一个更深层次的问题,然后将其包装在 InflateException 中。
一个常见问题是尝试膨胀加载可绘制资源的 ImageView 时出现内存不足异常。如果这些资源之一具有高像素分辨率,则将占用大量内存,从而导致膨胀异常。

因此,基本上要验证所有图像可绘制对象中的像素分辨率是否只是布局所需的最低分辨率。

The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException.
A common issue is an out of memory exception when trying to inflate an ImageView loading a drawable resource. If one of these resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.

So basically verify that the pixel resolution in all your image drawables is just the minimum necessary for your layout.

十级心震 2024-10-15 17:40:16

如果您使用支持库的 VectorDrawable 并且忘记使用 app:srcCompat 而不是 android:src ,也可能会发生这种情况

确切的错误是:
二进制 XML 文件行 #XX:膨胀类 ImageView 时出错

查看该链接

This can also happen if you use a VectorDrawable using support library and forgot to use app:srcCompat instead of android:src

Exact error is:
Binary XML file line #XX: Error inflating class ImageView

See that link

一梦等七年七年为一梦 2024-10-15 17:40:16

ViewFlipper 在布局膨胀期间将所有图像加载到内存中。因为我的图像很大,需要很多内存,所以我用 ImageSwitcher 替换了 ViewFlipper ,它可以像 ViewFlipper 一样用动画更改图像,但它只加载一个当时的图像。

ViewFlipper loads all images into memory during layout inflating. Because my images are big it takes many memory, I replaced ViewFlipper with ImageSwitcher which can change the images with animation like ViewFlipper but it loads only one image at the time.

夜深人未静 2024-10-15 17:40:16

仅使用一个构造函数创建自定义视图时,我遇到了同样的错误,请尝试为自定义视图定义所有构造函数。

   public CustomWebView(Context context) {
        super(context);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

I had the same error when creating custom view with only one constructor, try to define all constructor for your custom views.

   public CustomWebView(Context context) {
        super(context);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }
樱&纷飞 2024-10-15 17:40:16

我遇到了同样的错误,发现根本原因是:

使用应用程序上下文来膨胀视图。

使用 Activity Context 进行膨胀修复了该错误。

I encountered the same bug and found the root reason is:

Use Application Context to inflate view.

Inflating with Activity Context fixed the bug.

摇划花蜜的午后 2024-10-15 17:40:16

我知道这个问题已经得到解答,但我仍然抱着可能有人遇到此类问题的想法发帖。

就我而言,问题是我正在将应用程序加载到手机,该应用程序引用 res/layout/ 文件夹中的布局和 res/values/dimens 中 @dimens 的值,这里它是尝试访问的 font_22,它在 res/values-xlarge 中定义/尺寸。

我实际上正在更新现有项目的用户界面。

我遇到了这个问题,因为我使用的是 IDE Eclipse,在为布局文件夹编写 xml 时按 ctrl+space 进行提示,它会显示 value 以及 value-xlarge 文件夹中的所有值,无论我正在编写哪个文件夹。

我还知道两个文件中的值应该相同才能映射到不同的屏幕。

希望这可以帮助有人遇到这种愚蠢的问题。

I know the question is already answered but still I'm posting with thought that may someone run into this kind of problem.

In my case problem is i'm loading my application to phone which refer layouts from res/layout/ folder and values for @dimens from res/values/dimens here it's font_22 which it's trying to access and it's define in res/values-xlarge/dimens.

I'm actually updating UI of existing project.

I ran into this problem because I'm using IDE Eclipse where I ctrl+space for hint while writing xml for layout folder it displays all values from values as well as values-xlarge folder regardless of for which folder I'm writing.

I also know that the values in both files should be same to mapped for different screens.

Hope this may help someone run into this kind of silly problem.

岁月无声 2024-10-15 17:40:16

我发现了同样的错误,花了两天时间才确定错误是什么。

该错误只是因为我试图

使用: android:background而不是: app:srcCompat

在 SVG 文件中

。就您而言,我相信这就是

<ImageView 
    android:scaleType="fitXY" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/tour_11"      <-- the error is here !
 />

我建议使用它的方式,

将其添加到您的 build.gradle 应用程序

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

中,

<androidx.appcompat.widget.AppCompatImageView  <-- use **AppCompatImageView** not **ImageView**
        android:scaleType="fitXY" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:srcCompat="@drawable/tour_11"
     />

我希望这会有所帮助。

I found the same error, and it took two days to identify what the error was.

The error was simply because I was trying to use: android:background

Rather than: app:srcCompat

in an SVG file.

In your case, I believe this is it

<ImageView 
    android:scaleType="fitXY" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/tour_11"      <-- the error is here !
 />

I recommend using it this way

add this to your build.gradle app

android {  
   defaultConfig {  
     vectorDrawables.useSupportLibrary = true  
    }  
 }

and

<androidx.appcompat.widget.AppCompatImageView  <-- use **AppCompatImageView** not **ImageView**
        android:scaleType="fitXY" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:srcCompat="@drawable/tour_11"
     />

I hope this helps.

一场信仰旅途 2024-10-15 17:40:16

我遇到此错误是因为我选择主题作为材质主题。但当我尝试在 4.4.2 上运行应用程序时,它出现了此错误。

解决方案:选择 Theme_holo 作为主题

I had this error because i selected theme as Material theme. But as i was trying to run app on 4.4.2 it gave this error.

Solution : Select Theme_holo as theme

耳钉梦 2024-10-15 17:40:16

我的图片大小只有14Kb,但问题是设计师给了我1011px x 1819px(分辨率太高因此导致InflateException)

My picture size is only 14Kb but the problem is that the designer gave me 1011px x 1819px (resolution too high hence causing the InflateException)

淡莣 2024-10-15 17:40:16

如果有人遇到类似的问题,我在膨胀视图时遇到了这样的问题:

View.inflate(getApplicationContext(), R.layout.my_layout, null)

通过替换 getApplicationContext() 修复/code> 与 this

In case someone gets similar issues, I had such an issue while inflating the view:

View.inflate(getApplicationContext(), R.layout.my_layout, null)

fixed by replacing getApplicationContext() with this

执手闯天涯 2024-10-15 17:40:16

对我来说,日志猫中的错误消息实际上是不够的,所以我做了以下操作来找出导致问题的原因:(

在日志猫错误消息中,它说在我的 HomeFragment.java 中膨胀特定布局时发生错误)

  1. 我在布局膨胀之前放置了一个断点
  2. ,我在调试模式下运行应用程序,直到到达该特定断点,
  3. 我用光标选择了该行并在其上运行Evaluate expression
    • 运行>评估表达式alt - F8
  4. 结果向我展示了有关问题根源的更多信息,在我的例子中,这是一个使用 tools:targetApi="lollipop" 的可绘制文件 (该错误仅发生在较旧的设备上)。

For me, the error message was actually insufficient in the log cat, so here's what I did to figure out what caused the problem:

(In the log cat error message, it said the error occurred while inflating a specific layout in my HomeFragment.java)

  1. I put a breakpoint just before the layout was inflated
  2. I ran the application in debug mode until it reached that specific breakpoint
  3. I selected the line with my cursor and ran Evaluate expression on it:
    • Run > Evaluate Expression or alt - F8
  4. The result showed me more information about the source of the problem, which in my case, was a drawable file using tools:targetApi="lollipop" (the bug only occurred on older devices).
够钟 2024-10-15 17:40:16

对我来说,我的问题是我是

android:background="?attr/selectableItemBackground"

一个 LinearLayout 背景,一旦我删除它,测试就通过了。

For me, my issue was that I was

android:background="?attr/selectableItemBackground"

To a LinearLayout background, once I removed it the test passed.

断桥再见 2024-10-15 17:40:16

此链接可能会对您有所帮助。尝试检查您的清单是否存在问题。如果您可以让它再次发生,请发布整个堆栈跟踪,以便我们可以看到错误到底是什么。

编辑:我确信您已经检查过这一点,但是您用于 TourActivity 布局的 XML 文件的第 12 行是什么?

This link may help you. Try checking in your manifest for problems. If you can get it to happen again, post your entire stack trace so that we can see what the error actually is.

EDIT: I'm sure you've checked this, but what is on line 12 of the XML file you use for the TourActivity layout?

故人如初 2024-10-15 17:40:16

我知道这是一个已回答的问题,但我看不到我面临的原因。

Android Studio 将我的可绘制对象放置在 /drawable-V24 中
我的模拟器是API 23。所以,最终它找不到它。

解决方案是将所有可绘制对象移动到 /drawable 文件夹(否 -24)。

I know it is an answered question, but I do not see the cause that I faced.

It was that Android Studio placed my drawables in /drawable-V24
My emulator is API 23. So, eventually it can not find it.

The solution was to move all drawables to /drawable folder (no -24).

少女净妖师 2024-10-15 17:40:16

您应该将图像文件从“drawable-24”文件夹复制到“drawable”文件夹。

You should copy the image files from the "drawable-24" folder to the "drawable" folder.

总攻大人 2024-10-15 17:40:16
  • 我只是解决这个问题,只需从drawable(v24)中删除您的图像,然后将其粘贴到对我有用的drawable文件夹中。

  • I just solve this issue just delete your images from drawable(v24) and just paste it in drawable folder this works for me.

十六岁半 2024-10-15 17:40:16

我遇到了同样的错误,我解决了将可绘制对象从文件夹可绘制-mdpi 移动到文件夹可绘制的问题。我花了一些时间才意识到,因为在 Eclipse 中一切都运行良好,而在 Android Studio 中我却遇到了这些丑陋的运行时错误。

编辑注释:
如果您要从 Eclipse 迁移到 Android Studio,并且您的项目来自 Eclipse,则可能会发生这种情况,因此请注意,Android Studio 中的情况与 Eclipse 略有不同。

I had the same error and I solved moving my drawables from the folder drawable-mdpi to the folder drawable. Took me some time to realize because in Eclipse everything worked perfectly while in Android Studio I got these ugly runtime errors.

Edit note:
If you are migrating from eclipse to Android Studio and your project is coming from eclipse it may happen, so be careful that in Android Studio things a little differs from eclipse.

猫卆 2024-10-15 17:40:16

我刚才遇到了这个问题,并设法弄清楚它是什么。在我的值中引用了导致问题的颜色。因此,手动定义它,而不是使用下拉建议中的一个。然后它就起作用了!

I had this problem just now and managed to figure out what it was. Was referencing a colour in my values that was causing problems. So defined it manually instead of using one from the dropdown suggestions.Then it worked!

栖迟 2024-10-15 17:40:16

就我而言,当我使用浮动操作按钮并设置android:backgroundTint="#000"时,会发生此错误。然后只要不设置 backgroundTint 问题就解决了。
希望对您有帮助。

In my case,this error happen when I use the Floating action button and set android:backgroundTint="#000". Then just don't set backgroundTint and problem solved.
Hope it's helpful for you.

万水千山粽是情ミ 2024-10-15 17:40:16

我遇到了同样的问题,它通过删除可绘制文件夹中图像前面的 (24) 的可绘制-v24 并将其替换为普通可绘制来解决。

i had the same issue and it solved by removing drawable-v24 with (24) in front of images in drawable folder and replacing them with ordinary drawables.

宛菡 2024-10-15 17:40:16

通过将所有可绘制项目从可绘制-v24 移动到可绘制来解决此问题

Solved it by moving all my drawable items from drawable-v24 to drawable

女中豪杰 2024-10-15 17:40:16

当我在 API lvl 16 上运行我的应用程序时,我遇到了同样的错误(26 很好)。这是因为我在我的可绘制形状中使用了 ?attrr/colorAccent

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

    <corners android:radius="8dp" />

    <solid android:color="@attr/colorAccent" />

</shape>

用常规颜色替换它解决了我的问题。

I had same error when I ran my app on API lvl 16 (26 was fine). It was because I used ?attrr/colorAccent in my shape drawable:

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

    <corners android:radius="8dp" />

    <solid android:color="@attr/colorAccent" />

</shape>

Replacing that with a regular color fixed my problem.

把回忆走一遍 2024-10-15 17:40:16

就我而言,我必须指定在布局文件中使用的库 UI 组件的完整包名称。

In my case I've to specify the complete package name of library UI component that I use in my layout file.

北座城市 2024-10-15 17:40:16

我知道这个帖子已经很老了,但仍然回答它,以免其他人度过不眠之夜。

我正在重构一个旧项目,其布局文件都包含硬编码
属性,例如 android:maxLength = 500。所以我决定将其注册到我的
res/dimen 文件为 500

使用我的 res-value 完成了近 30 个布局文件的重构。你猜怎么着?下次我运行我的项目时,它开始抛出相同的 InflateException

作为解决方案,需要重做所有更改并保持所有这些值与以前相同。

TLDR;

第 1 步:一切运行良好。

第 2 步:为了加强维护,我将 android:maxLength = 500 替换为 500android: maxLength = @dimen/max_length ,这就是一切出错的地方(因 InflateException 崩溃)。

第 3 步:全部运行不良

第 4 步:再次用 android:maxLength = 500 替换 android:maxLength = @dimen/max_length 重新完成所有工作。一切都已修复。

第5步:一切运行良好。

I know this thread is old, but still answering it so that no-one else should spend sleepless nights.

I was refactoring an old project, whose layout files all contained hardcoded
attributes such as android:maxLength = 500. So I decided to register it in my
res/dimen file as <dimen name="max_length">500</dimen>.

Finished refactoring almost 30 layout files with my res-value. Guess what? the next time I ran my project it started throwing the same InflateException.

As a solution, needed to redo my all changes and keep all-those values as same as before.

TLDR;

step 1: All running good.

step 2: To boost my maintenance I replaced android:maxLength = 500 with <dimen name="max_length">500</dimen> and android:maxLength = @dimen/max_length , that's where it all went wrong(crashing with InflateException).

step 3: All running bad

step 4: Re-do all my work by again replacing android:maxLength = @dimen/max_length with android:maxLength = 500.Everything got fixed.

step 5: All running good.

嗳卜坏 2024-10-15 17:40:16

只需移动图像或形状

  • <块引用>

    drawable-v24到drawable文件夹

    输入图片此处描述

InflateException:

android.view.InflateException: Binary XML file line #32: Error inflating class androidx.appcompat.widget.SearchView
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
    at com.foamkart.Fragment.SearchFragment.onCreateView(SearchFragment.kt:37)

just move image or shape

  • drawable-v24 to drawable folder



    enter image description here

InflateException:

android.view.InflateException: Binary XML file line #32: Error inflating class androidx.appcompat.widget.SearchView
    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
    at com.foamkart.Fragment.SearchFragment.onCreateView(SearchFragment.kt:37)
吖咩 2024-10-15 17:40:16

我也遇到了类似的问题。虽然对于任何人来说,这可能是代码中各种不良用法的问题,例如

  1. XML 中的错误布局标签
  2. 将大量资源直接加载到 ImageView 中,导致 OOM
  3. 样式使用问题。

一个最容易被忽视的因素可能是在夸大视图时使用正确的上下文。请检查您是否没有在需要 Activity 上下文的地方使用 ApplicationContext。虽然,ApplicationContext可能不会总是出错,但根据您的视图层次结构,它可能至关重要。

我通过错误的上下文解决了我的问题(在 4 天内使用 ApplicationContext 而不是 Activity!所以尝试一下是否可以解决。快乐编码!

I also faced a similar issue. While for anyone this may be an issue of various bad usages in Code such as

  1. Wrong Layout tag in XML
  2. Loading of heavy resource directly into ImageView resulting in OOM
  3. Issues with usage of styles.

One most ignored factor may be usage of correct Context while inflating views. Please check that you are not using ApplicationContext where an Activity context is required. While, ApplicationContext may not end up in error always, but depending upon your view hierarchy it may be crucial.

I resolved my issue with a BAD context (using ApplicationContext instead of Activity in a span of 4 days! So try if that solves. Happy Coding!!

╰つ倒转 2024-10-15 17:40:16

我遇到了同样的问题,我在 xml 中使用了视图标签而不是视图。替换为 View 类解决了该问题。

希望它也对你有帮助..

I had faced the same issue, I had used view tag in xml instead of View. Replacing to View class fixed the issue.

Hope it helps for you too..

甜尕妞 2024-10-15 17:40:16

我们需要检查 API 版本。我曾经给我的 LinearLayout 提供背景颜色,就像

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/as_royalblue"
        android:orientation="vertical"></LinearLayout>

肯定我有同样的错误,在 drawable 文件夹

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:endColor="@color/royalblue_s"
        android:startColor="@color/royalblue_e" />
</shape>

中的 as_royalblue.xml 以及如何我修复了它,实际上这似乎是 Api 问题,所以我们需要检查 api 级别是否高于 API 24,以便我们能够使用我们喜欢的方式。但如果低于 24,我们需要避免使用,只是给出正常颜色或一种颜色而不是颜色渐变混合颜色。

fun checkAPI_N(): Boolean {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
            return true
        else
            return false
    }

给你的线性布局 id 并设置背景(如果可以的话)

 if(UtilKotlin.checkAPI_N()){
            linlay_act_menu_container.setBackgroundResource(R.drawable.a_6)
            linlay_act_menu_logo.setBackgroundResource(R.drawable.as_strain)
        }else {//todo normal color background setting}

We need to check API Version. I used to give background color to my LinearLayout like

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/as_royalblue"
        android:orientation="vertical"></LinearLayout>

for sure I had the same error, as_royalblue.xml inside drawable folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:endColor="@color/royalblue_s"
        android:startColor="@color/royalblue_e" />
</shape>

and how I fixed it, actually it seems Api problem so we need to check the api level if it is above API 24 so we are able to use the way we like. But if it is under 24 we need to avoid usage, juts give a normal color or one color not color gradential mixed one.

fun checkAPI_N(): Boolean {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
            return true
        else
            return false
    }

give id to your linearlayouts and set backgrounds if its ok

 if(UtilKotlin.checkAPI_N()){
            linlay_act_menu_container.setBackgroundResource(R.drawable.a_6)
            linlay_act_menu_logo.setBackgroundResource(R.drawable.as_strain)
        }else {//todo normal color background setting}
情仇皆在手 2024-10-15 17:40:16

对我来说,发生这种情况是因为我尝试在同一布局文件中将 xml 矢量图形图像与普通 png 混合,

只有在我用 png 替换 xml 矢量图形后它才开始工作

For me it happened because I tried to mix xml vector graphics images with ordinary png in the same layout file,

only after I replaced the xml vector graphics with pngs it started to work

痴者 2024-10-15 17:40:16

我在一个奇怪的设备上的 Crashlytics 中遇到了同样的错误:
Motorola One Vision Android 5.1 和 20 GB(免费)RAM,已 root
该设备最初配备 Android 9.0、4 GB RAM

可能有人试图破解我当前正在开发的应用程序,并且在处理多 APK 时遇到问题。因此无法找到可绘制对象并且应用程序会崩溃

I had the same error in Crashlytics from a strange device:
Motorola One Vision Android 5.1 and 20 GB (free) RAM, rooted
This device comes originally with Android 9.0, 4 GB RAM

Probably someone is trying to hack the app I'm currently developing and has problems dealing with multi-APKs. So drawables can't be found and the app delivers the crash

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文