Binary XML file line #4: Error inflating class 及OOM异常
2016-12-30 14:31
281 查看
Binary XML file line #4: Error inflating class 及OOM异常
程序可以编译通过并运行,但是在部分机型上出现 Binary XML file line #4: Error inflating class 及java.lang.OutOfMemoryError: Failed to allocate a 74649612 byte allocation with 4194208 free bytes and 9MB until OOM异常。解决方法:
不要在XML文件中设置图片,如android:background=”@drawable/bg”,android:src=”@drawable/bg”,需要在Java代码中设置。public BitmapDrawable getdrawable(int res){ BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; //获取资源图片 InputStream is = this.getResources().openRawResource(res); Bitmap bitmap = BitmapFactory.decodeStream(is,null, opt); try { is.close(); } catch (IOException e) { e.printStackTrace(); } return new BitmapDrawable(this.getResources(),bitmap); } ImageView iv=(ImageView) view.findViewById(R.id.iv); iv.setImageDrawable(getdrawable(R.drawable.bg));
至于相关原理请自行百度。
http://jingyan.baidu.com/article/ed2a5d1f3191d109f6be17e8.html
http://www.eoeandroid.com/thread-326343-1-1.html
相关文章推荐
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android 运行时异常 Binary XML file line # : Error inflating class
- Android运行时异常“Binary XML file line # : Error inflating class”
- android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- android异常之形如:android.view.InflateException: Binary XML file line #165: Error inflating class的解决办法
- 解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- Android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class”
- Android运行时异常“Binary XML file line # : Error inflating class” 分类: Android界面和组件 2014-09-12 00:19 94人阅读 评论(0) 收藏
- Android运行时异常“Binary XML file line # : Error inflating class