【发布时间】:2011-11-26 19:31:20
【问题描述】:
当我的活动布局中存在某些元素时,我在运行我的应用程序时遇到问题。我有以下布局,当我包含“空格”元素时出现问题:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="@string/foursquare" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/foursquare_button"
android:layout_alignParentLeft="true"
android:text="@string/yelp" />
<Space
android:layout_width="match_parent"
android:layout_height="100px"
android:layout_weight="0.18" />
</LinearLayout>
我得到的错误是这样的:
11-26 11:14:09.875:E/AndroidRuntime(10485):致命异常:main
...
11-26 11:14:09.875: E/AndroidRuntime(10485): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.infoit.nfc.activity/com.infoit.nfc.activity.ViewTag}: android.view .InflateException:二进制 XML 文件第 23 行:膨胀类空间时出错
...
11-26 11:14:09.875:E/AndroidRuntime(10485):原因:android.view.InflateException:二进制 XML 文件第 23 行:膨胀类空间时出错
...
11-26 11:14:09.875: E/AndroidRuntime(10485): 由: java.lang.ClassNotFoundException: android.view.Space in loader dalvik.system.PathClassLoader[/data/app/com.infoit.nfc.activity -2.apk]
...
如果我删除 Space 元素,一切都会变得非常敏锐。即使我认为定义 xmlns 可以解决问题,它也无法找到 Space 类。我觉得这很简单,但我想念它。
【问题讨论】:
-
您使用 API 14 吗?空间布局需要 SDK 14
-
啊,有道理。我在 API 14 上进行开发,但将其部署到 Gingerbread 手机上。因此,如果我使用的是合适的冰淇淋三明治手机,这可能不会给出错误。谢谢!
标签: android android-layout classnotfoundexception