Android.Views.InflateException:二进制XML文件行#1:在SetContentView上输出类<unknown>时出错

时间:2018-05-31 17:47:45

标签: c# android visual-studio xamarin exception

我正在开发一个C#android应用程序,它包含3个活动和3个布局。主要活动包括3个按钮,每个按钮将用户传递到特定的应用程序。第一个按钮转到FirstAct,它包含一些textViews和一个将用户重新加入MainActivity的按钮。现在单击返回按钮后,我重新单击MainActivity中的第一个按钮,将抛出此异常。

FirstAct.cs

protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    try
    {
        SetContentView(Resource.Layout.FirstLay);
        reBtn.Click += delegate
        {
            StartActivity(typeof(MainActivity));
        };
    }
    catch (Java.Lang.Exception ex)
    {
        Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
    }
 }

FirstLay

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="8dp"
    android:id="@+id/progressBar1"
    android:max="8"
    android:layout_marginTop="15dp" />
<TextView
    android:text="ما هو جنسك ؟"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    android:textDirection="anyRtl"
    android:textSize="22dip"
    android:layout_marginTop="50dp"
    android:gravity="center" />
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/radioGroup1"
    android:layout_marginTop="70dp">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:id="@+id/radioButton1"
        android:text="ذكر"
        android:layout_marginLeft="50dp"
        android:textSize="20dip" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="أنثى"
        android:id="@+id/radioButton2"
        android:layout_marginLeft="120dp"
        android:textSize="20dip" />
</RadioGroup>
<EditText
    android:inputType="number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/age"
    android:maxLength="3"
    android:visibility="gone" />
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/radioGroup2"
    android:visibility="gone"
    android:layout_marginTop="70dp">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:id="@+id/radioButton3"
        android:text="يومياً"
        android:layout_marginLeft="50dp"
        android:textSize="20dip"
        android:visibility="gone" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ليس كل يوم"
        android:id="@+id/radioButton4"
        android:layout_marginLeft="100dp"
        android:textSize="20dip"
        android:visibility="gone" />
</RadioGroup>
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/radioGroup3"
    android:layout_marginTop="70dp"
    android:visibility="gone">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="نعم"
        android:layout_marginLeft="50dp"
        android:textSize="20dip"
        android:id="@+id/radioButton5"
        android:visibility="gone" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="لا"
        android:id="@+id/radioButton6"
        android:layout_marginLeft="160dp"
        android:textSize="20dip"
        android:visibility="gone" />
</RadioGroup>
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/radioGroup4"
    android:visibility="gone"
    android:layout_marginTop="70dp">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="نعم"
        android:layout_marginLeft="50dp"
        android:textSize="20dip"
        android:id="@+id/radioButton7"
        android:visibility="gone" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="لا"
        android:id="@+id/radioButton8"
        android:layout_marginLeft="160dp"
        android:textSize="20dip"
        android:visibility="gone" />
</RadioGroup>
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/radioGroup5"
    android:layout_marginTop="70dp"
    android:visibility="gone">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:text="نعم"
        android:layout_marginLeft="50dp"
        android:textSize="20dip"
        android:id="@+id/radioButton9"
        android:visibility="gone" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="لا"
        android:id="@+id/radioButton10"
        android:layout_marginLeft="160dp"
        android:textSize="20dip"
        android:visibility="gone" />
</RadioGroup>
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView5"
    android:text="ادخل طولك (بالسنتيمتر):"
    android:visibility="gone" />
<EditText
    android:inputType="number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/height"
    android:visibility="gone"
    android:maxLength="3" />
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView6"
    android:text="ادخل وزنك (بالكيلوغرام):"
    android:visibility="gone" />
<EditText
    android:inputType="number"
    android:id="@+id/weight"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:maxLength="3" />
<TextView
    android:text="النتيجة: "
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/BMI"
    android:visibility="gone" />
<EditText
    android:inputType="number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/waist"
    android:visibility="gone"
    android:layout_marginTop="70dp"
    android:maxLength="3" />
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/radioGroup6"
    android:orientation="horizontal"
    android:visibility="gone"
    android:layout_marginTop="70dp">
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="false"
        android:id="@+id/radioButton11"
        android:text="نعم، مباشرون"
        android:visibility="gone"
        android:textSize="16dip" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="نعم، غير مباشرون"
        android:id="@+id/radioButton12"
        android:visibility="gone"
        android:textSize="16dip" />
    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="لا"
        android:id="@+id/radioButton13"
        android:visibility="gone"
        android:textSize="15dip" />
</RadioGroup>
<TextView
    android:text="جاري حساب النتيجة.."
    android:id="@+id/textView7"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="22dip"
    android:gravity="center"
    android:visibility="gone"
    android:layout_marginTop="150dp" />
<ProgressBar
    style="?android:attr/progressBarStyleHorizontal"
    android:id="@+id/progressBar2"
    android:layout_width="match_parent"
    android:layout_height="12dp"
    android:visibility="gone" />
<TextView
    android:layout_height="430dp"
    android:id="@+id/textView4"
    android:textSize="20dip"
    android:visibility="gone"
    android:gravity="center"
    android:text="مجموع النقاط (score):"
    android:layout_width="330dp"
    android:layout_marginTop="25dp"
    android:layout_marginLeft="20dp"
    android:background="@drawable/res"
    android:textStyle="bold"
    android:paddingLeft="40dp"
    android:paddingRight="40dp"
    android:paddingTop="70dp" />
<Button
    android:layout_width="230dp"
    android:layout_height="170dp"
    android:id="@+id/button3"
    android:background="@drawable/btn"
    android:layout_gravity="center"
    android:text="العودة"
    android:textSize="22dip"
    android:visibility="gone" />
<LinearLayout
    android:orientation="horizontal"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="111dp"
    android:id="@+id/linearLayout1"
    android:layout_marginTop="60dp">
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/back"
        android:layout_weight="1" />
    <TextView
        android:id="@+id/textView1"
        android:gravity="center"
        android:text="1/9"
        android:textSize="22dip"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1" />
    <Button
        android:id="@+id/button1"
        android:enabled="false"
        android:background="@drawable/arr"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1" />
</LinearLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:id="@+id/textView3"
        android:textSize="22dip"
        android:visibility="gone"
        android:textStyle="italic"
        android:paddingRight="5dp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:id="@+id/view1"
        android:background="@drawable/ll"
        android:layout_above="@id/textView3"
        android:visibility="gone" />
 </RelativeLayout>
 </LinearLayout>

输出

05-31 22:50:16.619 I/art     (11433): Alloc sticky concurrent mark sweep GC freed 1086(84KB) AllocSpace objects, 1(68KB) LOS objects, 5% free, 
 242MB/256MB, paused 240us total 5.171ms
05-31 22:50:16.619 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.629 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.629 I/art     (11433): Alloc partial concurrent mark sweep GC freed 147(6KB) AllocSpace objects, 0(0B) LOS objects, 5% free, 
 242MB/256MB, paused 268us total 8.105ms
05-31 22:50:16.629 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.639 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.639 I/art     (11433): Alloc concurrent mark sweep GC freed 73(14KB) AllocSpace objects, 0(0B) LOS objects, 5% free, 
  242MB/256MB, paused 277us total 9.346ms
05-31 22:50:16.639 I/art     (11433): Forcing collection of SoftReferences for 16MB allocation
05-31 22:50:16.639 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.649 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.649 I/art     (11433): Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 5% free, 242MB/256MB, paused 264us total 8.461ms
05-31 22:50:16.649 W/art     (11433): Throwing OutOfMemoryError "Failed to allocate a 16777228 byte allocation with 14484880 free bytes and 13MB until OOM"
05-31 22:50:16.649 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.649 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.654 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.659 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.659 I/art     (11433): Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 5% free, 242MB/256MB, paused 238us total 6.470ms
05-31 22:50:16.659 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.669 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.669 I/art     (11433): Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 5% free, 242MB/256MB, paused 274us total 8.247ms
05-31 22:50:16.669 I/art     (11433): Forcing collection of SoftReferences for 16MB allocation
05-31 22:50:16.669 I/art     (11433): Starting a blocking GC Alloc
05-31 22:50:16.674 I/art     (11433): Clamp target GC heap from 258MB to 256MB
05-31 22:50:16.674 I/art     (11433): Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 5% free, 242MB/256MB, paused 243us total 8.064ms
05-31 22:50:16.674 W/art     (11433): Throwing OutOfMemoryError "Failed to allocate a 16777228 byte allocation with 14484880 free bytes and 13MB until OOM"
05-31 22:50:16.679 D/skia    (11433): --- allocation failed for scaled bitmap
Unhandled Exception:

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class <unknown>`

奇怪的是,当我第一次在Mainactivity中单击该按钮时,第一个活动仅在第二次抛出异常时才会启动而没有问题。我首先想到的是,我所拥有的背景图像可能会导致这种情况,所以我将其删除了,但这并没有奏效。然后我放了NoHistory = true但也没用。此外,我还尝试在单击返回按钮时启动MainActivity之前完成活动。所以我不知道是什么导致了这个问题,请你帮我找一下?

0 个答案:

没有答案