当我使用包含制表符的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
,这将是其中一个选项卡。其他选项卡目前看起来非常相似:
<?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 ---
我希望有人能帮我理解这里的问题,我真的很想弄清楚我可能做错了什么…
发布于 2013-04-16 08:57:09
您的ImagePage.axml不需要TabHost和TabWidget标记;您的Main.axml中应该只有这些标记。选项卡的布局将包含在FrameLayout中的Main.axml中,因此每个选项卡布局文件只包含ne。
发布于 2013-04-18 22:55:33
经过进一步的搜索,我发现了这个问题,那是在我的主发射器里。问题是,在创建每个类时,我试图在"spec.SetContent (意图);“行中调用类”意图“,而我应该调用的是它的实例,”意向“(没有大写"i")。所以基本上它是拼写错误,但它没有显示为我的语法错误,因为有一个类具有相同的名称.
不管怎样,谢谢你!
发布于 2014-05-08 11:19:18
这可能是相当不相干的,但谁还在想这个错误可能来自哪里-可能指向正确的方向。
我也遇到了同样的问题,原来我从AXML中引用的自定义控件有一个错误的指定路径,即控件在任何地方都找不到。
https://stackoverflow.com/questions/16041169
复制相似问题