开发者社区> 问答> 正文

android.view.InflateException: Binary XM?报错

谁能帮帮我 啊?一直内存溢出,在其他手机上就运行正常,就一个大屏手机一直报错

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zgan.community/com.zgan.community.activity.CommunityPolicitalDetailActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>

  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  at android.app.ActivityThread.access$600(ActivityThread.java:130)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:137)
  at android.app.ActivityThread.main(ActivityThread.java:4745)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
  at android.app.Activity.setContentView(Activity.java:1867)
  at com.zgan.community.activity.CommunityPolicitalDetailActivity.onCreate(CommunityPolicitalDetailActivity.java:56)
  at android.app.Activity.performCreate(Activity.java:5008)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  ... 11 more
 Caused by: java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Constructor.constructNative(Native Method)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
  ... 23 more
 Caused by: java.lang.OutOfMemoryError
  at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
  at android.content.res.Resources.loadDrawable(Resources.java:2057)
  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
  at android.view.View.<init>(View.java:3336)
  at android.view.ViewGroup.<init>(ViewGroup.java:427)
  at android.widget.LinearLayout.<init>(LinearLayout.java:176)
  at android.widget.LinearLayout.<init>(LinearLayout.java:172)
  ... 26 more

展开
收起
爱吃鱼的程序员 2020-06-22 11:27:39 512 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    引用来自“huiztechzhiyuan”的答案

    引用来自“huiztechzhiyuan”的答案

    1.图片太大.2.设置图片软引用

    可能性1:

    程序其他地方加载了太多bitmap导致这个地方内存不够了,我觉得这个可能性比较大

    把你这个Activity单独抠出来放到一个独立工程里跑一遍,就跑界面,排除其他逻辑的影响,看看还会不会OOM


    可能性2:

    如果还会OOM,我怀疑你这个layout某些图片用了比较大的分辨率(200-300应该不至于),而那台手机分辨率是比xhdpi还大一个挡位,所以系统自动进行了放大才加载。

    Bydefault,Androidscalesyourbitmapdrawables(.png,.jpg,and.giffiles)andNine-Patchdrawables(.9.pngfiles)sothattheyrenderattheappropriatephysicalsizeoneachdevice.Forexample,ifyourapplicationprovidesbitmapdrawablesonlyforthebaseline,mediumscreendensity(mdpi),thenthesystemscalesthemupwhenonahigh-densityscreen,andscalesthemdownwhenonalow-densityscreen.

    谢谢,原来在xxhdpi下再放个图片文件,系统就不会吧hdpi下的图片拿来缩放从而导致OOM了是图片分辨率太大,都720x1169了接近300K了你那个LinearLayout里头塞了啥Drawable啊,多大?放在Res下哪个Drawable目录很多图标我是放在xhdpi中的,有几张200-300多的背景图放在了hdpi中1.图片太大.2.设置图片软引用我直接在布局里面android:background设置图片的嘛,这个怎么软引用哦

    引用来自“huiztechzhiyuan”的答案

    1.图片太大.2.设置图片软引用

    http://www.eoeandroid.com/thread-326343-1-1.html

    这篇说要在Java代码里面完成设置图片,要注意及时释放掉。

    http://stackoverflow.com/questions/18385362/high-resolution-image-outofmemoryerror

    这票他说了一些图片压缩的措施,主要让我们参考官方文档

    : http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#read-bitmap

    参考参考呗

    2020-06-22 11:27:58
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载