=========== 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. poj1417 带权并查集+0/1背包

    题意:有一个岛上住着一些神和魔,并且已知神和魔的数量,现在已知神总是说真话,魔总是说假话,有 n 个询问,问某个神或魔(身份未知),问题是问某个是神还是魔,根据他们的回答,问是否能够确定哪些是神哪些是 ...

  2. Nginx-limit_req限速配置示例

    #以用户二进制IP地址,定义三个漏桶,滴落速率1-3req/sec,桶空间1m,1M能保持大约16000个(IP)状态 limit_req_zone $binary_remote_addr zone= ...

  3. js字符串函数

    JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...

  4. 【C语言模拟实现】浮点数-转-定点数

    要想超神,就要什么都精! 知识准备: 1. 输出浮点数的十六进制形式?(利用指针输出) 将浮点数指针-转换成-整型指针,以十六进制的格式输出指针内容. 示例程序: #include<stdio. ...

  5. c语言编程中%g是什么格式

    %g用来输出实数,它根据数值的大小,自动选f格式或e格式(选择输出时占宽度较小的一种),且不输出无意义的0.即%g是根据结果自动选择科学记数法还是一般的小数记数法 printf("%g\n& ...

  6. 【Reporting Services 报表开发】— 数据表存储格式修改

    文本框 Format属性:日期:输入d(表示简易日期).2007/5/1 0:00:00   输入d之后 变成 2007/5/1 金额:输入C0(表示货币),系统会根据设定值产生对应的货币符号,至于0 ...

  7. [原]一个简单的Linux TCP Client所涉及到的头文件

    今天在Linux环境下写了一个最简单的TCP Client程序,没想到Linux环境下的头文件竟然这么分散,让我这样的菜鸟很是郁闷啊.编译成功的代码如下: #include <iostream& ...

  8. [Spring] IOC - study

    Spring IOC简单注入例子,本例子使用JUnit进行测试.Spring版本:3.2 项目结构: Spring所需引用的JAR包: Spring XML配置: springContext.xml ...

  9. JSP MVC

    Java的MVC玩起来比.Net的有意思,因为每一步你都知道它是如何运作的,都由自己去实现.而在.Net的MVC中,你却不知道一个Controller是如何对应到View中的,因为MS给了你IDE上的 ...

  10. 程序员书单_J2EE专题

    Enterprise JavaBeans 3.0中文版(第5版) http://download.csdn.net/detail/shenzhq1980/9104015 J2EE设计模式 http:/ ...