在我的活动中,是什么导致了这个Android.Views.InflateException?

在我的活动中,是什么导致了这个Android.Views.InflateException?,android,xamarin.android,Android,Xamarin.android,这只是在我移动了布局中的一些元素之后才开始发生的。如果您认为这有助于解决问题,我也可以共享XML代码 以下是导致异常的活动: <?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=

这只是在我移动了布局中的一些元素之后才开始发生的。如果您认为这有助于解决问题,我也可以共享XML代码

以下是导致异常的活动:

<?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" />

堆栈跟踪:

    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
Android.Views.InflateException:二进制XML文件行#1:膨胀类Android.widget.ImageButton时出错-->Java.Lang.Reflect.InvocationTargetException:-->Java.Lang.OutOfMemoryError:未能分配182250012字节的4194304个空闲字节和74MB,直到OOM为止
在java.lang.OutOfMemoryError:未能分配182250012字节的分配,其中4194304个可用字节和74MB直到OOM
位于dalvik.system.VMRuntime.newNonMovableArray(本机方法)
在android.graphics.BitmapFactory.NativeDecodesset(本机方法)上
位于android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
位于android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
位于android.graphics.drawable.drawable.createFromResourceStream(drawable.java:988)
位于android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
位于android.content.res.Resources.loadDrawable(Resources.java:2381)
位于android.content.res.TypedArray.getDrawable(TypedArray.java:749)
在android.widget.ImageView上
在android.widget.ImageButton.(ImageButton.java:86)
在android.widget.ImageButton.(ImageButton.java:82)
在android.widget.ImageButton.(ImageButton.java:78)
位于java.lang.reflect.Constructor.newInstance(本机方法)
位于android.view.LayoutInflater.createView(LayoutInflater.java:607)
位于com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
位于android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
位于android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
在android.view.LayoutInflater.充气(LayoutInflater.java:365)
位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
位于android.app.Activity.setContentView(Activity.java:2145)
at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.n_onCreate(本机方法)
位于md54421ba596fa8cc5324701d9bb904102d.pickCityPage.onCreate(pickCityPage.java:29)
位于android.app.Activity.performCreate(Activity.java:5990)
位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303)
位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415)
在android.app.ActivityThread.access$900(ActivityThread.java:152)
位于android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328)
位于android.os.Handler.dispatchMessage(Handler.java:102)
位于android.os.Looper.loop(Looper.java:135)
位于android.app.ActivityThread.main(ActivityThread.java:5301)
位于java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:723)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
---内部异常堆栈跟踪的结束---
在java.lang.reflect.InvocationTargetException
位于java.lang.reflect.Constructor.newInstance(本机方法)
位于android.view.LayoutInflater.createView(LayoutInflater.java:607)
位于com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
位于android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
位于android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
在android.view.LayoutInflater.inflate(LayoutInflater.java:504)
在android.view.LayoutInflater.inflate(LayoutInflater.java:414)
在android.view.LayoutInflater.充气(LayoutInflater.java:365)
位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
位于android.app.Activity.setContentView(Activity.java:2145)
at md54421ba596fa8cc5324701d9bb904102d.pickCityPage.n_onCreate(本机方法)
位于md54421ba596fa8cc5324701d9bb904102d.pickCityPage.onCreate(pickCityPage.java:29)
位于android.app.Activity.performCreate(Activity.java:5990)
位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
位于android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2303)
位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2415)
在android.app.ActivityThread.access$900(ActivityThread.java:152)
位于android.app.ActivityThread$H.handleMessage(ActivityThread.java:1328)
位于android.os.Handler.dispatchMessage(Handler.java:102)
位于android.os.Looper.loop(Looper.java:135)
位于android.app.ActivityThread.main(ActivityThread.java:5301)
位于java.lang.reflect.Method.invoke(本机方法)
在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:723)
位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:613)
在时,原因是:java.lang.OutOfMemoryError:未能分配182250012字节分配,4194304个可用字节和74MB,直到OOM
位于dalvik.system.VMRuntime.newNonMovableArray(本机方法)
在android.graphics.BitmapFactory.NativeDecodesset(本机方法)上
位于android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
位于android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
位于android.graphics.drawable.drawable.createFromResourceStream(drawable.java:988)
位于android.content.res.Resources.loadDrawableForCookie(Resources.java:2474)
在android.content.res.Resource
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);
                }
            }
        });
    }
}
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() {
    }
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="GlideImageView">
        <attr name="image_resource" format="integer"/>
    </declare-styleable>
</resources>