android.view.InflateException:二进制XML文件行#1:在Xamarin Studio

时间:2015-09-24 08:11:29

标签: c# layout xamarin xamarin-studio inflate-exception

几天,当我启动我的应用程序时,它停止工作并将此错误返回给我:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
[MonoDroid] at Android.Runtime.JNIEnv.CallObjectMethod (intptr,intptr,Android.Runtime.JValue*) [0x00064] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:195
[MonoDroid] at Android.Views.LayoutInflater.Inflate (int,Android.Views.ViewGroup) [0x0006d] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-16/src/generated/Android.Views.LayoutInflater.cs:646
[MonoDroid] at TMF.HomeGridAdapter.GetView (int,Android.Views.View,Android.Views.ViewGroup) [0x0001c] in c:\Users\Emilie\Desktop\TMF\TMF\Accueil\Controller\HomeGridAdapter.cs:68
[MonoDroid] at Android.Widget.BaseAdapter.n_GetView_ILandroid_view_View_Landroid_view_ViewGroup_ (intptr,intptr,int,intptr,intptr) [0x0001a] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-16/src/generated/Android.Widget.BaseAdapter.cs:509
[MonoDroid] at (wrapper dynamic-method) object.dac95129-53b3-413b-87bd-5107706f40b2 (intptr,intptr,int,intptr,intptr) <IL 0x00023, 0x00063>
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
[MonoDroid]     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
[MonoDroid]     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
[MonoDroid]     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
[MonoDroid]     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
[MonoDroid]     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
[MonoDroid]     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
[MonoDroid]     at md58aed98370e11680441fda4f25bb6cc81.HomeGridAdapter.n_getView(Native Method)
[MonoDroid]     at md58aed98370e11680441fda4f25bb6cc81.HomeGridAdapter.getView(HomeGridAdapter.java:55)
[MonoDroid]     at android.widget.AbsListView.obtainView(AbsListView.java:2255)
[MonoDroid]     at android.widget.GridView.onMeasure(GridView.java:1044)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
[MonoDroid]     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
[MonoDroid]     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
[MonoDroid]     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
[MonoDroid]     at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
[MonoDroid]     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
[MonoDroid]     at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
[MonoDroid]     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
[MonoDroid]     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
[MonoDroid]     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
[MonoDroid]     at android.view.View.measure(View.java:16497)
[MonoDroid]     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
[MonoDroid]     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
[MonoDroid]     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
[MonoDroid]     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
[MonoDroid]     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
[MonoDroid]     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
[MonoDroid]     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
[MonoDroid]     at android.view.Choreographer.doFrame(Choreographer.java:544)
[MonoDroid]     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
[MonoDroid]     at android.os.Handler.handleCallback(Handler.java:733)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)
[MonoDroid] Caused by: java.lang.reflect.InvocationTargetException
[MonoDroid]     at java.lang.reflect.Constructor.constructNative(Native Method)
[MonoDroid]     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[MonoDroid]     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
[MonoDroid]     ... 58 more
[MonoDroid] Caused by: java.lang.OutOfMemoryError
[MonoDroid]     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
[MonoDroid]     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
[MonoDroid]     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
[MonoDroid]     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
[MonoDroid]     at android.content.res.Resources.loadDrawable(Resources.java:2115)
[MonoDroid]     at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
[MonoDroid]     at android.widget.ImageView.<init>(ImageView.java:129)
[MonoDroid]     at android.widget.ImageView.<init>(ImageView.java:119)
[MonoDroid]     ... 61 more
[AndroidRuntime] Shutting down VM

我将Xamarin Studio用于我的应用程序,这是我的代码:

public override View GetView(int position, View convertView, ViewGroup parent)
{
    var item = items[position];
    View view = convertView;
    if (view == null)  // no view to re-use, create new
    {
        view = context.LayoutInflater.Inflate (Resource.Layout.HomeGridAdapterLayout, null);
        view.LayoutParameters = new GridView.LayoutParams (440, 380);
    }

    //Si pas un produit TMF (Rend invisible le QRCode Transparence TMF)
    if (!item.TMF) {
        view.FindViewById<ImageView> (Resource.Id.ivQRCode).Visibility = ViewStates.Invisible;
    }

    //Si pas un produit en promotion (Rend invisible le logo promo
    if (!item.Promo) {
        view.FindViewById<ImageView> (Resource.Id.ivPromo).Visibility = ViewStates.Invisible;
    }

    view.FindViewById<TextView>(Resource.Id.tvTitre).Text = item.Titre;


    if(item.Image != null)
        view.FindViewById<ImageView>(Resource.Id.ivHomeGrid).SetImageBitmap(Static.getRoundCornerBitmap(context,item.Image,5,true,true,true,true));
    else view.FindViewById<ImageView>(Resource.Id.ivHomeGrid).SetImageBitmap(Static.getRoundCornerBitmap(context,BitmapFactory.DecodeResource(context.Resources,Resource.Drawable.img_default),5,true,true,true,true));
    view.FindViewById<TextView> (Resource.Id.tvOrigine).Text = "Origine: " + item.Origine;
    view.FindViewById<TextView> (Resource.Id.tvPrix).Text = "Prix: " + item.Prix;
    return view;
}

这是调用Layout的函数。这是布局的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="444dp"
    android:layout_height="387dp"
    android:id="@+id/relativeLayout1"
    android:background="@drawable/bkg_home_product"
    android:paddingBottom="8dp"
    android:paddingRight="4dp">
    <ImageView
        android:id="@+id/ivHomeGrid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/img_default"
        android:scaleType="fitXY" />
    <TextView
        android:id="@+id/tvPrix"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignLeft="@+id/ivHomeGrid"
        android:layout_alignRight="@+id/ivHomeGrid"
        android:layout_alignBottom="@+id/ivHomeGrid"
        android:gravity="center_vertical"
        android:text="@string/Prix"
        android:textColor="#282826"
        android:textSize="20dp"
        android:paddingLeft="10dp"
        android:paddingRight="72dp"
        android:background="@color/blanc" />
    <TextView
        android:text="@string/Origine"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_above="@id/tvPrix"
        android:id="@+id/tvOrigine"
        android:gravity="center_vertical"
        android:textSize="20dp"
        android:textColor="#282826"
        android:paddingLeft="10dp"
        android:background="@color/blanc"
        android:paddingRight="72dp" />
    <TextView
        android:text="Huitres marenne d'oléron - fine de clair verte - n˚3"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_above="@id/tvOrigine"
        android:id="@+id/tvTitre"
        android:gravity="center_vertical"
        android:paddingLeft="10dp"
        android:textSize="25dp"
        android:textColor="#282826"
        android:background="@color/blanc"
        android:textAllCaps="true"
        android:paddingRight="72dp" />
    <ImageView xmlns:tools="http://schemas.android.com/tools"
        android:src="@drawable/tag_tmf"
        android:layout_width="72dp"
        android:layout_height="96dp"
        android:id="@+id/ivQRCode"
        tools:visibility="visible"
        android:layout_alignBottom="@id/ivHomeGrid"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="true" />
    <ImageView xmlns:tools="http://schemas.android.com/tools"
        android:src="@drawable/corner_en_promo_white"
        android:layout_width="127dp"
        android:layout_height="114dp"
        android:id="@+id/ivPromo"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        tools:visibility="visible"
        android:alpha="0.8" />
</RelativeLayout>

我真的不明白为什么它不再起作用,我尝试清理并重建我的项目但没有成功。我的图像位于drawable - hdpi文件夹中,分辨率为444x387。

1 个答案:

答案 0 :(得分:0)

非常简单。您的答案写在系统日志中:

Caused by: java.lang.OutOfMemoryError

解决方案:在AndroidManifest文件中增加应用程序的堆内存。

这篇文章也可能对你有所帮助:Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget