Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class 错误

在我的项目中,遇到一个奇葩的问题,那就是当我退出,重新进入加载页的时候,就报了下面的错误,看到红色的文字:

java.lang.RuntimeException: Unable to start activity ComponentInfo{***.ui.login.WelcomeActivity}:android.view.InflateException: Binary XML file line #7: Error inflating class<unknown>atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2304)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)at android.app.ActivityThread.access$700(ActivityThread.java:165)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:5450)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:525)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)at dalvik.system.NativeStart.main(Native Method)

Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class <unknown>atandroid.view.LayoutInflater.createView(LayoutInflater.java:626)at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)at android.view.LayoutInflater.inflate(LayoutInflater.java:498)at android.view.LayoutInflater.inflate(LayoutInflater.java:398)at android.view.LayoutInflater.inflate(LayoutInflater.java:354)at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)at android.app.Activity.setContentView(Activity.java:1956)at ***.ui.login.WelcomeActivity.initView(WelcomeActivity.java:44)at ***.ui.BaseActivity.onCreate(BaseActivity.java:51)at android.app.Activity.performCreate(Activity.java:5369)at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)... 11 moreCaused by: java.lang.reflect.InvocationTargetExceptionat java.lang.reflect.Constructor.constructNative(Native Method)at java.lang.reflect.Constructor.newInstance(Constructor.java:417)at android.view.LayoutInflater.createView(LayoutInflater.java:600)... 25 more

Caused by: java.lang.OutOfMemoryError

at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)at android.content.res.Resources.loadDrawable(Resources.java:2988)at android.content.res.TypedArray.getDrawable(TypedArray.java:602)at android.view.View.<init>(View.java:3563)at android.widget.ImageView.<init>(ImageView.java:125)at android.widget.ImageView.<init>(ImageView.java:121)... 28 more

咋一看,是布局文件出问题了,然后就去看了,发现写的没有错误(一开始还以为是android系统的问题),如下

我的布局文件

分析了几种可能性:

1、布局文件出错了;Binary XML file line #7: Error inflating class <unknown>at

2、引用了相同名字的资源文件,导致嵌套调用,资源溢出;java.lang.OutOfMemoryError

3、资源文件有问题(比如图片过大);--最后发现真的是这个问题,一开始突破有200k,然后改成63k,还是不行,最后改成22k,就解决了;

4、其他未知原因;


建议:

1、Android的界面能用png最好是用png,因为32位的png颜色过渡平滑且支持透明。我用的是jpg,要改过来才行;--解决:真的是图片格式问题,必须要用到png格式的才不会oom;

你可能感兴趣的:(Android控件)