bug_ _图片_android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>

=========== 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个月前)
时间: 2024-08-25 10:43:27

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

bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class &lt;unknown

===== 2 ==== 1  android.view.InflateException: Binary XML file line #2: Error inflating class <unknown 莫名其妙的出现这个错,看了logcat 说是什么二进制xml错误啥的... 不过后来发现,这个一般都是给eclipse项目中添加图片等资源时出现的一些bug,看似添加到项目中,其实没有,或者是你是选取的引用模式,而你在外面又把那个图片给重命名了,所以在jvm运行时会报错, 说什么xml lin

android.view.InflateException: Binary XML file line #8: Error inflating class &lt;unknown&gt;

错误打印部分代码: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> 02-02 11:43:11.420: E/AndroidRuntime(25333): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 02-02 11:43:11.420: E/AndroidRuntime(25

android.view.InflateException: Binary XML file line#2: Error inflating class&lt;unknown&gt;

最近在做安卓程序的引导页问题,每次当加载引导页的时候总是报错,说未知的填充错误,很是郁闷啊. 从stackoverflow找到的解决方案: 当运行的时候,安卓会改变图片的大小(基于屏幕的尺寸和分辨率),安卓使用bitmap去重新改变图片的尺寸.所以,这个是内存非常敏感的行为.一个快速的解决方法是,将比较大的图片复制到drawable-ldpi, mdpi, hdpi 文件夹中.安卓会自动选择合适的文件并且重新改变他们的大小, (上面是对stackoverflow的解释) ------------

android 细节之android.view.InflateException: Binary XML file line #95: Error inflating class(out of m)

今天的异常很有意思,叫做android.view.InflateException: Binary XML file line #95: Error inflating class(out of memory) . 其实是因为out of memory,导致 xml是不可能被充气成功,因此activity的onCreate方法中, setContentView(R.layout.***)也就不可能成功调用. 他出现在我有多个教学动画,并且播放的动画,是基于imageView,imageView的

android.view.InflateException: Binary XML file line #95: Error inflating class(out of memory) 。异常

android.view.InflateException: Binary XML file line #95: Error inflating class(out of memory) . 其实是因为out of memory,导致 xml是不可能被充气成功,因此activity的onCreate方法中, setContentView(R.layout.***)也就不可能成功调用. 他出现在我有多个教学动画,并且播放的动画,是基于imageView,imageView的背景是我们项目的大型图片

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.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class 异常解决方案: 是因为设置background的图片太大了,造成了内存溢出,在Activity设置onCreate

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

这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面.    当时,我仔细检查了一下自己的代码,并没有发现什么问题,在logcat上显示的报错如下:AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class(这是其中报错的最主要的一行信息).  于是我在百度上几乎查看

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

此错误比较难定位,场景是这样的:在一个widget中使用了自定义控件,始终会报 android.view.InflateException: Binary XML file line #2: Error inflating class...这个错误. 最后实在没有办法了,写了一个demo中只有一个重写的textview(仅仅是继承textview并无其他代码),将其引入到布局文件仍然报同样的错误. 后来经过查找资料,发现removeview比支持复杂的view,连listview都不支持,更不用

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.lang.RuntimeException: Unable to start activity ComponentInfo{com.edaixi.activity/com.edaixi.activity.PriceCenterActivity}: android.view.InflateExcept