2016-10-28 2 views
1

Es begann erst kürzlich, nachdem ich einige Elemente in meinem Layout verschoben habe. Ich kann den XML-Code auch teilen, wenn Sie denken, dass das helfen würde, das Problem zu lösen.Was in meiner Aktivität verursacht diese Android.Views.InflateException?

Hier ist die Aktivität, die die Ausnahme verursacht:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android" 
p1:layout_width="match_parent" 
p1:layout_height="match_parent" 
p1:id="@+id/relativeLayout1" 
p1:background="@drawable/pickcitybackground"> 
<ImageView 
    p1:src="@drawable/pick" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/pick" 
    p1:layout_marginLeft="50dp" 
    p1:layout_marginTop="90dp" /> 
<ImageButton 
    p1:src="@drawable/austinbutton" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/austinButton" 
    p1:background="#02ffffff" 
    p1:scaleType="centerCrop" 
    p1:layout_marginTop="90dp" 
    p1:layout_marginLeft="210dp" /> 
<ImageButton 
    p1:src="@drawable/nashvillebutton" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/nashvilleButton" 
    p1:scaleType="centerCrop" 
    p1:background="#02ffffff" 
    p1:layout_marginLeft="50dp" 
    p1:layout_marginTop="265dp" /> 
<ImageButton 
    p1:src="@drawable/newyorkbutton" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/newyorkButton" 
    p1:scaleType="centerCrop" 
    p1:background="#02ffffff" 
    p1:layout_marginTop="265dp" 
    p1:layout_marginLeft="210dp" /> 
<ImageButton 
    p1:src="@drawable/sanfranbutton" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/sanfranButton" 
    p1:scaleType="centerCrop" 
    p1:background="#02ffffff" 
    p1:layout_marginTop="435dp" 
    p1:layout_marginLeft="50dp" /> 
<ImageButton 
    p1:src="@drawable/seattlebutton" 
    p1:layout_width="60dp" 
    p1:layout_height="60dp" 
    p1:id="@+id/seattleButton" 
    p1:layout_marginLeft="210dp" 
    p1:background="#02ffffff" 
    p1:scaleType="centerCrop" 
    p1:layout_marginTop="435dp" /> 

Der Stack-Trace:

Android.Views.InflateException: Binary XML file line #1: Error inflating class android.widget.ImageButton ---> Java.Lang.Reflect.InvocationTargetException: ---> Java.Lang.OutOfMemoryError: Failed to allocate a 182250012 byte allocation with 4194304 free bytes and 74MB until OOM 
    at java.lang.OutOfMemoryError: Failed to allocate a 182250012 byte allocation with 4194304 free bytes and 74MB until OOM 
    at at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
    at at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
    at at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
    at at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
    at at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988) 
    at at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474) 
    at at android.content.res.Resources.loadDrawable(Resources.java:2381) 
    at at android.content.res.TypedArray.getDrawable(TypedArray.java:749) 
    at at android.widget.ImageView.<init>(ImageView.java:146) 
    at at android.widget.ImageButton.<init>(ImageButton.java:86) 
    at at android.widget.ImageButton.<init>(ImageButton.java:82) 
    at at android.widget.ImageButton.<init>(ImageButton.java:78) 
    at at java.lang.reflect.Constructor.newInstance(Native Method) 
    at at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378) 
    at at android.app.Activity.setContentView(Activity.java:2145) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.n_onCreate(Native Method) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.onCreate(pickCityPage.java:29) 
    at at android.app.Activity.performCreate(Activity.java:5990) 
    at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303) 
    at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415) 
    at at android.app.ActivityThread.access$900(ActivityThread.java:152) 
    at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328) 
    at at android.os.Handler.dispatchMessage(Handler.java:102) 
    at at android.os.Looper.loop(Looper.java:135) 
    at at android.app.ActivityThread.main(ActivityThread.java:5301) 
    at at java.lang.reflect.Method.invoke(Native Method) 
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:723) 
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613) 
    --- End of inner exception stack trace --- 
    at java.lang.reflect.InvocationTargetException 
    at at java.lang.reflect.Constructor.newInstance(Native Method) 
    at at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378) 
    at at android.app.Activity.setContentView(Activity.java:2145) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.n_onCreate(Native Method) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.onCreate(pickCityPage.java:29) 
    at at android.app.Activity.performCreate(Activity.java:5990) 
    at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303) 
    at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415) 
    at at android.app.ActivityThread.access$900(ActivityThread.java:152) 
    at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328) 
    at at android.os.Handler.dispatchMessage(Handler.java:102) 
    at at android.os.Looper.loop(Looper.java:135) 
    at at android.app.ActivityThread.main(ActivityThread.java:5301) 
    at at java.lang.reflect.Method.invoke(Native Method) 
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:723) 
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613) 
    at Caused by: java.lang.OutOfMemoryError: Failed to allocate a 182250012 byte allocation with 4194304 free bytes and 74MB until OOM 
    at at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
    at at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
    at at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
    at at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
    at at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988) 
    at at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474) 
    at at android.content.res.Resources.loadDrawable(Resources.java:2381) 
    at at android.content.res.TypedArray.getDrawable(TypedArray.java:749) 
    at at android.widget.ImageView.<init>(ImageView.java:146) 
    at at android.widget.ImageButton.<init>(ImageButton.java:86) 
    at at android.widget.ImageButton.<init>(ImageButton.java:82) 
    at at android.widget.ImageButton.<init>(ImageButton.java:78) 
    at ... 25 more 
    --- End of inner exception stack trace --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a7] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12083 
    at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00068] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:31 
    at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00017] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:5253 
    at Quickies.Android.pickCityPage.OnCreate (Android.OS.Bundle bundle) [0x0000e] in /Users/michaelsloan/Desktop/Quickies/Android/Quickies/pickCityPage.cs:28 
    at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.App.Activity.cs:2550 
    at at (wrapper dynamic-method) System.Object:e8fa207e-6c2f-4c69-899e-9bfde46df162 (intptr,intptr,intptr) 
    at android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.ImageButton 
    at at android.view.LayoutInflater.createView(LayoutInflater.java:633) 
    at at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
    at at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
    at at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
    at at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:504) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
    at at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378) 
    at at android.app.Activity.setContentView(Activity.java:2145) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.n_onCreate(Native Method) 
    at at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.onCreate(pickCityPage.java:29) 
    at at android.app.Activity.performCreate(Activity.java:5990) 
    at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303) 
    at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415) 
    at at android.app.ActivityThread.access$900(ActivityThread.java:152) 
    at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328) 
    at at android.os.Handler.dispatchMessage(Handler.java:102) 
    at at android.os.Looper.loop(Looper.java:135) 
    at at android.app.ActivityThread.main(ActivityThread.java:5301) 
    at at java.lang.reflect.Method.invoke(Native Method) 
    at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:723) 
    at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613) 
    at Caused by: java.lang.reflect.InvocationTargetException 
    at at java.lang.reflect.Constructor.newInstance(Native Method) 
    at at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
    at ... 23 more 
    at Caused by: java.lang.OutOfMemoryError: Failed to allocate a 182250012 byte allocation with 4194304 free bytes and 74MB until OOM 
    at at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
    at at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 
    at at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) 
    at at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) 
    at at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988) 
    at at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474) 
    at at android.content.res.Resources.loadDrawable(Resources.java:2381) 
    at at android.content.res.TypedArray.getDrawable(TypedArray.java:749) 
    at at android.widget.ImageView.<init>(ImageView.java:146) 
    at at android.widget.ImageButton.<init>(ImageButton.java:86) 
    at at android.widget.ImageButton.<init>(ImageButton.java:82) 
    at at android.widget.ImageButton.<init>(ImageButton.java:78) 
    at ... 25 more 
+0

Es ist zu Image id bezogen. – AndroidHacker

+0

post you Layout xml –

+0

Ich habe das XML-Layout veröffentlicht. Irgendwelche Ideen? Ich würde eine Richtung lieben! Ich lese gerade, wie [große Bitmaps effizient zu laden, damit ich diese Ausnahme nicht bekomme] (https://developer.xamarin.com/recipes/android/resources/general/load_large_bitmaps_efficiently/) @MarcoPierucci –

Antwort

0

Sie haben etwas in Ihrem Layout, die viel Speicher benötigt. Wahrscheinlich Bitmaps, weiß ich nicht ohne XML-Layout.

OutOfMemoryError: Failed to allocate a 182250012 byte allocation with 4194304 free

0

Ihre Bilder sind zu groß. Sie sollten mit einem Bild loader Bibliothek (ich empfehle Glide) betrachten die Bilder zu laden, anstatt nur im Stich gelassen Android es tun

EDIT (weil Android ziemlich schlecht ist.): My GlideImageView:

import android.annotation.TargetApi; 
import android.content.Context; 
import android.content.res.TypedArray; 
import android.util.AttributeSet; 
import android.view.View; 
import android.widget.ImageView; 

import com.bumptech.glide.Glide; 

/** 
* Created by Zhuinden on 2016.05.07.. 
*/ 
public class GlideImageView 
     extends ImageView { 
    public GlideImageView(Context context) { 
     super(context); 
     init(context, null, 0); 
    } 

    public GlideImageView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(context, attrs, 0); 
    } 

    public GlideImageView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(context, attrs, defStyleAttr); 
    } 

    @TargetApi(21) 
    public GlideImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
     init(context, attrs, defStyleAttr); 
    } 

    int drawableResource = 0; 

    private void init(Context context, AttributeSet attributeSet, int defStyle) { 
     TypedArray a = null; 
     if(defStyle != 0) { 
      a = getContext().obtainStyledAttributes(attributeSet, R.styleable.GlideImageView, defStyle, 0); 
     } else { 
      a = getContext().obtainStyledAttributes(attributeSet, R.styleable.GlideImageView); 
     } 
     drawableResource = a.getResourceId(0, 0); 
     a.recycle(); 

     ViewUtils.waitForMeasure(this, new ViewUtils.OnMeasuredCallback() { 
      @Override 
      public void onMeasured(View view, int width, int height) { 
       if(!isInEditMode()) { 
        if(drawableResource != 0) { 
         Glide.with(getContext()).load(drawableResource).dontAnimate().into(GlideImageView.this); 
        } 
       } else { 
        setImageResource(drawableResource); 
       } 
      } 
     }); 
    } 
} 

Und

public class ViewUtils { 
    public interface OnMeasuredCallback { 
     void onMeasured(View view, int width, int height); 
    } 

    public static void waitForMeasure(final View view, final OnMeasuredCallback callback) { 
     int width = view.getWidth(); 
     int height = view.getHeight(); 

     if(width > 0 && height > 0) { 
      callback.onMeasured(view, width, height); 
      return; 
     } 

     view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 
      @Override 
      public boolean onPreDraw() { 
       final ViewTreeObserver observer = view.getViewTreeObserver(); 
       if(observer.isAlive()) { 
        observer.removeOnPreDrawListener(this); 
       } 

       callback.onMeasured(view, view.getWidth(), view.getHeight()); 

       return true; 
      } 
     }); 
    } 

    private ViewUtils() { 
    } 
} 

Und

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="GlideImageView"> 
     <attr name="image_resource" format="integer"/> 
    </declare-styleable> 
</resources> 
+0

Dies ist das erste Mal, dass ich von Bildlade-Bibliotheken höre, aber sie scheinen selbsterklärend zu sein. Eine schnelle Suche führte mich zu diesem (https://components.xamarin.com/gettingstarted/universalimageloader) einen für Xamarin. –

+0

Persönlich habe ich eine benutzerdefinierte Ansicht erstellt, die das Bild nach dem 'onMeasure' mit Glide geladen hat. Niemals 'ImageView' verwendet, weil es dumm ist und nicht mehr genügend Arbeitsspeicher zur Verfügung steht. Ich hätte den Code gepostet, aber ich bin von meinem Telefon und auf meiner Suche nach meinem Internet zu Hause zu reparieren :) – EpicPandaForce

+0

Ich mache meine App mit C# mit Xamarin, so hoffentlich kann ich Ihre Lösung für einige Hinweise verwenden. –

Verwandte Themen