Android.Views.InflateException
当我使用setContentView (Resource.Layout.Main)
包含选项卡并且不明白为什么时,我得到了一个。
我一直在试图找到其他人遇到我的问题,但这似乎Android.Views.InflateException
是一个非常普遍的错误信息,因为人们似乎在各种情况下都能得到它。我已经尝试了一些我看到提到的东西,但到目前为止它们并没有帮助我。
奇怪的是,完全相同的Main.axml
代码可以在不同的试用应用程序中完美运行,但我无法让它在这个应用程序中运行。
我在编程应用程序方面相当新,我不知道它是否有任何区别,但我正在使用Xamarin Studio。我尝试了其他一些简单的应用程序来使用所有新事物,并且它们运行起来没有太多麻烦。
这是我的主启动器的代码:
using System;
using System.IO;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
//using Mono.Data.Sqlite;
namespace MultiFuncTest1
{
[Activity (MainLauncher=true, Label="@string/app_name", Theme="@android:style/Theme.NoTitleBar")]
public class MultiFuncTest1 : TabActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set the view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// ----------------------------------------------------------------------------------------------------
// TABS
// ----------------------------------------------------------------------------------------------------
// Declares TabSpec and Intent
TabHost.TabSpec spec;
Intent intent;
// Creates and Intent To Start and Activity for the Image-tab.
intent = new Intent (this, typeof (ImageActivity));
intent.AddFlags (ActivityFlags.NewTask);
// Starts a TabSpec for the Image-tab and adds it to the TabHost
spec = TabHost.NewTabSpec ("image");
spec.SetIndicator ("Image", Resources.GetDrawable (Resource.Drawable.Icon));
spec.SetContent (Intent);
TabHost.AddTab (spec);
// Creates and Intent To Start and Activity for the Icon-tab.
intent = new Intent (this, typeof (IconActivity));
intent.AddFlags (ActivityFlags.NewTask);
// Starts a TabSpec for the Icon-tab and adds it to the TabHost
spec = TabHost.NewTabSpec ("icons");
spec.SetIndicator ("Icons", Resources.GetDrawable (Resource.Drawable.Icon));
spec.SetContent (Intent);
TabHost.AddTab (spec);
// Creates and Intent To Start and Activity for the Image-tab.
intent = new Intent (this, typeof (ItemListActivity));
intent.AddFlags (ActivityFlags.NewTask);
// Starts a TabSpec for the Image-tab and adds it to the TabHost
spec = TabHost.NewTabSpec ("itemList");
spec.SetIndicator ("Item List", Resources.GetDrawable (Resource.Drawable.Icon));
spec.SetContent (Intent);
TabHost.AddTab (spec);
// Creates and Intent To Start and Activity for the Image-tab.
intent = new Intent (this, typeof (WebLinkActivity));
intent.AddFlags (ActivityFlags.NewTask);
// Starts a TabSpec for the Image-tab and adds it to the TabHost
spec = TabHost.NewTabSpec ("webLink");
spec.SetIndicator ("Web Links", Resources.GetDrawable (Resource.Drawable.Icon));
spec.SetContent (Intent);
TabHost.AddTab (spec);
TabHost.CurrentTab = 1;
}
}
}
这是我的 ImageActivity 的代码,它应该是选项卡之一。目前所有选项卡活动都有非常相似的代码,因为我只是想让大纲工作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace MultiFuncTest1
{
[Activity (Label = "ImageActivity")]
public class ImageActivity : Activity
{
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
//SetContentView (Resource.Layout.ImagePage);
TextView textview = new TextView (this);
textview.Text = "This is the Artists tab";
SetContentView (textview);
}
}
}
这是我的Main.axml
:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>
而ImagePage.axml
which 将是选项卡之一。其他选项卡目前看起来非常相似:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="@drawable/Icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/iPimageView1" />
</LinearLayout>
这是我得到的堆栈跟踪的第一部分。在“托管异常堆栈跟踪结束”部分之后,跟踪会持续很长时间,并以“和 250 多行”之类的东西结束,或者类似的东西,所以我认为这些不那么重要吗?如果他们有帮助,请告诉我,我也会添加它们:
Android.Views.InflateException: Binary XML file line #24: Error inflating class <unknown>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00024] in /Users/builder/data/lanes/monodroid-lion-bs1/03814ac5/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:616
at Android.App.Activity.SetContentView (int) [0x0006b] in /Users/builder/data/lanes/monodroid-lion-bs1/03814ac5/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:3119
at MultiFuncTest1.MultiFuncTest1.OnCreate (Android.OS.Bundle) [0x00009] in d:\Mobile App Dev\Projects\MultiFuncTest1\MultiFuncTest1\MultiFuncTest1.cs:24
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-bs1/03814ac5/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1490
at at (wrapper dynamic-method) object.46f87726-02c8-486d-b95c-c7cce7c7d106 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
at
at --- End of managed exception stack trace ---
我希望有人可以帮助我理解这里的问题,我真的很想了解我可能做错了什么......