=========== 1   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)

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

00k的图片直接在xml里设置的话在个别手机很容易内存溢出.试试这个吧/

public static Bitmap loadBitmapImage(int resId,int inSize,Context context) {
     //resetPurgeTimer();
     String strId =String.valueOf(resId);
      if(mImageCache.containsKey(strId)) {
       SoftReference<Bitmap> softReference = mImageCache.get(strId);
             Bitmap bitmap = softReference.get();             
             if(null != bitmap)
                 return bitmap;

}
           BitmapFactory.Options options = new BitmapFactory.Options();
      options.inSampleSize = inSize;
      options.inPreferredConfig = Bitmap.Config.ARGB_4444;
  Bitmap bitmap =null;
  try{
   bitmap = BitmapFactory.decodeResource(context.getResources(), resId);           
         mImageCache.put(strId, new SoftReference<Bitmap>(bitmap));
  }catch(OutOfMemoryError e){
   System.gc();
   bitmap =null;
  }
           return bitmap;

}

public static Drawable readDrawable(Context context, int resId) { 
BitmapFactory.Options opt = new BitmapFactory.Options(); 
opt.inPreferredConfig = Bitmap.Config.RGB_565; 
opt.inPurgeable = true; 
opt.inInputShareable = true; 
// 获取资源图片 
InputStream is = context.getResources().openRawResource(resId); 
return new BitmapDrawable(BitmapFactory.decodeStream(is, null, opt)); 

网上说decodeStream内存占用少一些,把你的decodeResouse换成decodeStream 会不会更好一些 
 

可能性1:

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

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

可能性2:

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

By default, Android scales your bitmap drawables (.png,.jpg, and.giffiles) and Nine-Patch drawables (.9.pngfiles) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen.

 

--- 共有 2 条评论 ---

  • 四档路飞谢谢,原来在xxhdpi下再放个图片文件,系统就不会吧hdpi下的图片拿来缩放从而导致OOM了 (10个月前)

bug_ _图片_android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>的更多相关文章

  1. bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class <unknown

    ========= 5.0     android异常“android.view.InflateException: Binary XML file line # : Error inflating ...

  2. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.L ...

  3. Android项目部署时,发生AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class错误

    这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面.    当时,我仔细检查了一下自己的代码,并 ...

  4. Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃

    在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java. ...

  5. "android.uid.systemandroid.view.InflateException: Binary XML file line #7: Error inflating class android.webkit.WebView

    在android源码中编译app通过,运行时出现错误: "android.uid.systemandroid.view.InflateException: Binary XML file l ...

  6. widget自定义控件【android.view.InflateException: Binary XML file line #2: Error inflating class...】

    此错误比较难定位,场景是这样的:在一个widget中使用了自定义控件,始终会报 android.view.InflateException: Binary XML file line #2: Erro ...

  7. 异常 ndroid.view.InflateException: Binary XML file line #8: Error inflating class com.ouyang.test.MyView

    发现自定义view时出现ndroid.view.InflateException: Binary XML file line #8: Error inflating class com.ouyang. ...

  8. 错误解决:android.view.InflateException: Binary XML file line #11: Error inflating class com.tony.timepicker.TimePicker

    今天在做项目开发时遇到这么一个错误,完整的错误提示信息如下: java.lang.RuntimeException: Unable to start activity ComponentInfo{co ...

  9. TextInputLayout低版本bug :“android.view.InflateException: Binary XML file line #6 : Error inflating class Textview”

    开发中用到TextInputLayout配合TextInputEdittext做输入框,在android7.0 android8.0手机上运行正常,在异步android5.0.2的手机上,点击输入框就 ...

随机推荐

  1. java 四种内部类和内部接口

    /** * 常规内部类:常规内部类没有用static修饰且定义在在外部类类体中. * 1.常规内部类中的方法可以直接使用外部类的实例变量和实例方法. * 2.在常规内部类中可以直接用内部类创建对象 * ...

  2. (转)现代C++函数式编程

    本文转自:http://geek.csdn.net/news/detail/96636     现代C++函数式编程 C++ 函数式编程 pipeline 开发经验 柯里化 阅读2127    作者简 ...

  3. VGG-19 和 VGG-16 的 prototxt文件

    VGG-19 和 VGG-16 的 prototxt文件  VGG-19 和 VGG-16 的 prototxt文件 VGG-16:prototxt 地址:https://gist.github.co ...

  4. ruby杂记

    ruby基本类中的方法:puts Object.private_instance_methods

  5. ABBYY将JPEG文件转换成Word文档的方法

    日常工作中处理JPEG格式的图像文件时,有时需要转换成Word文档进行编辑,市场上应用而生了很多转换工具,相信不少人听说过OCR(光学字符识别)软件,可以用来转换图像文件,而在OCR软件中, ABBY ...

  6. add to svn ignore disabled

    The problem is that the folder is already under version control. Here's how I fix this type of probl ...

  7. C#, float.ToString()的一个坑

    下面代码的输出竟然是2.0: float a=1.95f;Debug.Log(a.ToString("0.0")); 如果想截取一位小数,可以: float a=1.95f; fl ...

  8. 【转】一个域名对应多个IP地址,接下来系统是依据什么决定使用哪个IP地址的?

    例如下图所示:nslookup http://www.sina.com.cn返回了多个IP地址,当使用curl通过域名进行访问时,则自动选择了其中一个地址进行访问,这个选择的过程里发生了什么事情? 绝 ...

  9. Redis持久化机制和恢复机制

    Redis持久化方式有两种: (1)RDB 对内存中数据库状态进行快照 (2)AOF 把每条写命令都写入文件,类似mysql的binlog日志 RDB 将Redis在内存中的数据库状态保存到磁盘里面, ...

  10. HttpClient简介 post get -转自ibm

    HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...