我收到错误但不知道原因。第一个代码块在第23行导致此错误。但是我有一个Main_Screen.axml文件,所以我不知道为什么会发生这种情况。我查了一下错误,它说我在.axml文件中有问题。这可能是一个我忽略的简单错误,因为它看起来很好。
using ...
...
namespace DM_App_Code_Fragment
{
[Activity(Label = "DM_App_Code_Fragment", MainLauncher = true, Icon = "@drawable/icon")]
public class MainScreen : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main_Screen);
Button show_quick_timer = FindViewById<Button> (Resource.Id.button1);
show_quick_timer.Click += delegate
{
StartActivity(typeof(QuickTimer.QuickTimer));
};
var show_new_recipe = FindViewById<Button>(Resource.Id.button2);
show_new_recipe.Click += (sender, e) =>
{
//StartActivity(typeof(CreateNewScreen));
};
var show_load_recipe = FindViewById<Button>(Resource.Id.button4);
show_load_recipe.Click += (sender, e) =>
{
//StartActivity(typeof(LoadRecipeScreen));
};
var show_view_running_timers = FindViewById<Button>(Resource.Id.button5);
show_view_running_timers.Click += (sender, e) =>
{
//StartActivity(typeof(ViewRunningTimersScreen));
};
}
}
}
这是.axml文件。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60.0dp"
android:layout_marginRight="60.0dp"
android:textStyle="bold"
android:textSize="40.0dp"
android:text="Timer App" />
<Button
Click=""
android:text="Quick Timer"
android:layout_width="310.0dp"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:layout_marginTop="100.0dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/space1" />
<Button
android:text="Create New"
android:layout_width="310.0dp"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_marginTop="150.0dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/space2" />
<Button
android:text="Load"
android:layout_width="310.0dp"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_marginTop="200.0dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/space3" />
<Button
android:text="View Running Timers"
android:layout_width="310.0dp"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:layout_marginTop="250.0dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/space4" />
<Button
android:text="Exit"
android:layout_width="310.0dp"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_marginTop="300.0dp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/space5" />
</RelativeLayout>
这是错误堆栈:
04-20 21:28:16.076 I/MonoDroid( 510): UNHANDLED EXCEPTION: Android.Views.InflateException: Exception of type 'Android.Views.InflateException' was thrown.
04-20 21:28:16.076 I/MonoDroid( 510): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:895
04-20 21:28:16.076 I/MonoDroid( 510): at Android.App.Activity.SetContentView (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:3243
04-20 21:28:16.076 I/MonoDroid( 510): at DM_App_Code_Fragment.MainScreen.OnCreate (Android.OS.Bundle) [0x00009] in c:\Users\JD\Desktop\DM_App_Code_Fragment __\DM_App_Code_Fragment v.03\DM_App_Code_Fragment\DM_App_Code_Fragment\Main_Screen.cs:23
04-20 21:28:16.076 I/MonoDroid( 510): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/7f0e3d3c/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1559
04-20 21:28:16.076 I/MonoDroid( 510): at (wrapper dynamic-method) object.6f0ff6a7-86fe-4c4c-9c83-f8e6b79d1576 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
04-20 21:28:16.076 I/MonoDroid( 510):