二进制 XML 文件第 2 行:膨胀类 android.widget.LinearLayout 时出错
我完全迷失了这个。我的应用程序在我的手机上并通过模拟器在 API 2.1 上完美运行。 我刚刚通过 2.2 模拟器运行它,但出现崩溃并出现以下错误:
04-27 20:29:41.293: ERROR/AndroidRuntime(341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebp/com.ebp.ebpMainMenu}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.os.Looper.loop(Looper.java:123)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:521)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at dalvik.system.NativeStart.main(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.Activity.setContentView(Activity.java:1622)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.ebp.ebpMainMenu.onCreate(ebpMainMenu.java:58)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): ... 11 more
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: java.lang.reflect.InvocationTargetException
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Constructor.constructNative(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): ... 21 more
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.nativeCreate(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.content.res.Resources.loadDrawable(Resources.java:1705)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.View.<init>(View.java:1850)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.View.<init>(View.java:1799)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.ViewGroup.<init>(ViewGroup.java:284)
在 main.xml 文件中,这里是第 2 行
<LinearLayout
android:id="@+id/linearLayout3"
android:background="@drawable/mainbackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
,这里是主线 58:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
I am completely lost with this one. My app works perfectly on API 2.1 on my handset and through the emulator.
I have just run it through a 2.2 emulator and I am getting a crash and this error:
04-27 20:29:41.293: ERROR/AndroidRuntime(341): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebp/com.ebp.ebpMainMenu}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.os.Looper.loop(Looper.java:123)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Method.invokeNative(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Method.invoke(Method.java:521)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at dalvik.system.NativeStart.main(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.Activity.setContentView(Activity.java:1622)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at com.ebp.ebpMainMenu.onCreate(ebpMainMenu.java:58)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): ... 11 more
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: java.lang.reflect.InvocationTargetException
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.widget.LinearLayout.<init>(LinearLayout.java:92)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Constructor.constructNative(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): ... 21 more
04-27 20:29:41.293: ERROR/AndroidRuntime(341): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.nativeCreate(Native Method)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.content.res.Resources.loadDrawable(Resources.java:1705)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.View.<init>(View.java:1850)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.View.<init>(View.java:1799)
04-27 20:29:41.293: ERROR/AndroidRuntime(341): at android.view.ViewGroup.<init>(ViewGroup.java:284)
In the main.xml file, here is line #2
<LinearLayout
android:id="@+id/linearLayout3"
android:background="@drawable/mainbackground"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
and here is main line 58:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引起:java.lang.OutOfMemoryError:位图大小超出VM预算
可能是这里真正的罪魁祸首。尝试使用较小的图像来查看是否是与内存相关的问题。查看这些链接以获取类似问题的示例:java.lang.OutOfMemoryError:位图大小超出 VM 预算 - android - 有多少图像?
从外部存储加载位图时出现 OutOfMemory 异常
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
may be the real culprit here. Try using smaller image to see if it is a memory-related issue.Check out these links for examples of similar issues: java.lang.OutOfMemoryError: bitmap size exceeds VM budget - android - how many images?
OutOfMemory exception when loading bitmap from external storage