【问题标题】:Xamarin Studio (Android) Error Inflating Class <unknown> Unless CleanedXamarin Studio (Android) 错误膨胀类 <unknown> 除非清理
【发布时间】:2014-10-14 01:23:23
【问题描述】:

问题:

在 Xamarin Studio 中修改我的 Android 项目中的 any 布局文件后,我的 mainlauncher (SplashActivity) 引发以下异常。异常继续抛出,直到我清理我的项目。


例外情况:

二进制 XML 文件第 17 行:膨胀类时出错


环境:

我正在使用以下工具:

Xamarin Studio: Version 5.2.1 (build 1)
Xamarin.Android: Version 4.1.0

具有以下相关设置:

最低 Android 版本:Android 4.3(API 级别 16)

电脑:

Windows 7 家庭高级版 SP1 (x64)

测试设备:

运行 Android 4.3 的三星 Galaxy S4


相关代码:

SplashLayout.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">
    <TextView
        android:text="Loading..."
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/SPLASH_messageText" />
</LinearLayout>

SplashActivity(修剪为仅 OnCreate)

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);
    SetContentView (Resource.Layout.SplashLayout);   // <-- this is where the exception is thrown
    MessageTextView = FindViewById<TextView> (Resource.Id.SPLASH_messageText);      // Get a reference to our message text view to update the user

    ThreadPool.QueueUserWorkItem (o => {
        InitialChecking();               // Check to make sure Google Play services are installed
    });
} // end OnCreate

我的研究:

以下是一些看似相关但与我目前的情况无关的问题列表。


其他信息:

  • 当我在调试前清理解决方案时,错误得到解决,直到我修改 any 布局文件。
  • 一旦抛出此异常,它将继续抛出,直到我清理解决方案。
  • 活动的 XML 只有一个文本视图,它不调用任何可绘制资源。此外,SplashLayout.axml 仅包含 12 行代码。

问题:

  • 可能导致此错误的原因是什么,在生产中是否会发生?

【问题讨论】:

  • 你的 textAppearance 属性中应该有问号吗?
  • @SpiritMachine 布局没有问题,textAppearance 属性中的问号也没有。不知何故,构建过程可能会有些奇怪。 OP,您使用的是什么版本的工具?
  • @Cheesebaron 我正在使用Xamarin Studio 5.2.1 build 1。我已经编辑了这个问题以反映这一点。另外,我省略了我的 InitialChecking() 方法,因为我不认为它是相关的,因为抛出异常的位置。如果有任何其他可能有用的信息,请告诉我,我会根据需要编辑我的问题。

标签: android android-layout xamarin.android xamarin-studio inflate-exception


【解决方案1】:

您能否尝试将此行添加到您的 axml 文件中: xmlns:app="http://schemas.android.com/apk/res-auto"

这听起来可能无关,但我曾经遇到过通货膨胀问题,并且通过这样做解决了。

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 2011-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    相关资源
    最近更新 更多