我的应用程序没有问题,直到我添加了几个图像按钮,(一个没有问题)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jarek.stratcaller/com.example.jarek.stratcaller.ChooseMapActivity}: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.jarek.stratcaller.ChooseMapActivity.onCreate(ChooseMapActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.jarek.stratcaller.ChooseMapActivity.onCreate(ChooseMapActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 1511784 free bytes and 1476KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:973)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2423)
at android.content.res.Resources.loadDrawable(Resources.java:2330)
at android.content.res.Resources.getDrawable(Resources.java:758)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:175)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1017)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2418)
at android.content.res.Resources.loadDrawable(Resources.java:2330)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3730)
at android.widget.TextView.<init>(TextView.java:634)
at android.widget.Button.<init>(Button.java:111)
at android.widget.Button.<init>(Button.java:107)
at android.widget.Button.<init>(Button.java:103)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:377)
at android.app.Activity.setContentView(Activity.java:2144)
at com.example.jarek.stratcaller.ChooseMapActivity.onCreate(ChooseMapActivity.java:18)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这是我的ChooseMapActivity类:
package com.example.jarek.stratcaller;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class ChooseMapActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_map);
/* TODO: Commentary to map settings */
Button Dust2_Button = (Button) findViewById(R.id.dust2_button);
Dust2_Button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(ChooseMapActivity.this, ChooseSideActivity.class));
}
});
}
}
和XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#6c6976"
tools:context=".ChooseMapActivity">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center_vertical">
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/dust2_button"
android:background="@drawable/dust2_custom_button"
android:layout_marginTop="15dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/cache_button"
android:layout_alignTop="@+id/dust2_button"
android:layout_toRightOf="@+id/dust2_button"
android:layout_toEndOf="@+id/dust2_button"
android:background="@drawable/cache_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/nuke_button"
android:layout_below="@+id/dust2_button"
android:layout_alignLeft="@+id/dust2_button"
android:layout_alignStart="@+id/dust2_button"
android:background="@drawable/nuke_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/mirage_button"
android:layout_below="@+id/nuke_button"
android:layout_alignLeft="@+id/nuke_button"
android:layout_alignStart="@+id/nuke_button"
android:background="@drawable/mirage_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/overpass_button"
android:layout_above="@+id/mirage_button"
android:layout_toRightOf="@+id/nuke_button"
android:layout_toEndOf="@+id/nuke_button"
android:background="@drawable/overpass_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/inferno_button"
android:layout_below="@+id/nuke_button"
android:layout_toRightOf="@+id/nuke_button"
android:layout_toEndOf="@+id/nuke_button"
android:background="@drawable/inferno_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/cobblestone_button"
android:layout_below="@+id/mirage_button"
android:layout_alignLeft="@+id/mirage_button"
android:layout_alignStart="@+id/mirage_button"
android:background="@drawable/cobblestone_custom_button"/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/train_button"
android:layout_alignTop="@+id/cobblestone_button"
android:layout_toRightOf="@+id/cobblestone_button"
android:layout_toEndOf="@+id/cobblestone_button"
android:background="@drawable/train_custom_button"/>
</RelativeLayout>
我试图找到解决方案,但对我而言,我的行:ChooseMapActivity类中的18个完全没问题,是什么想法?
答案 0 :(得分:1)
这出现在您的logcat中:
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 1511784 free bytes and 1476KB until OOM
这可能是因为位图较大,可能是图像较小。
答案 1 :(得分:0)
您的XML无效,您的第一个标记已关闭两次。删除此部分:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left|center_vertical">