2015-07-21 52 views
2

我的應用程序的工作原理沒有問題後,開始活動ComponentInfo,(一個沒有任何問題)的RuntimeException:無法直到我說幾個imagebuttons添加幾個imageButtons

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

你正在越來越'OutOfMemoryError'可能是因爲一個大的位圖,可能是較小的圖像 – omainegra

+0

這解決了一個問題,謝謝! – henorek

+0

您好@henorek,我張貼我的答案,所以你可以標記爲接受。 – omainegra

回答

1

這出現在你的logcat:

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 1511784 free bytes and 1476KB until OOM 

這可能是因爲大量位圖,可能與較小的圖像。

0

您的XML無效,您的第一個標記會關閉兩次。刪除這一部分:

android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="left|center_vertical"> 
+0

謝謝,但它不能解決問題 – henorek