[英]ClassNotFoundException for android.view.Space when running application
I'm having an issue running my application when certain elements exist in the layout of my activity. 当我的活动布局中存在某些元素时,我遇到运行应用程序的问题。 I have the following layout, and I have issue when I include the "Space" element: 我有以下布局,当我包含“Space”元素时,我遇到了问题:
<?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>
The error I get is this: 我得到的错误是这样的:
11-26 11:14:09.875: E/AndroidRuntime(10485): FATAL EXCEPTION: main 11-26 11:14:09.875:E / AndroidRuntime(10485):致命异常:主要
... ...
11-26 11:14:09.875: E/AndroidRuntime(10485): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infoit.nfc.activity/com.infoit.nfc.activity.ViewTag}: android.view.InflateException: Binary XML file line #23: Error inflating class Space 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): Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class Space 11-26 11:14:09.875:E / AndroidRuntime(10485):引起:android.view.InflateException:二进制XML文件行#23:错误膨胀类空间
... ...
11-26 11:14:09.875: E/AndroidRuntime(10485): Caused by: java.lang.ClassNotFoundException: android.view.Space in loader dalvik.system.PathClassLoader[/data/app/com.infoit.nfc.activity-2.apk] 11-26 11:14:09.875:E / AndroidRuntime(10485):引起:java.lang.ClassNotFoundException:loader dalvik.system.PathClassLoader中的android.view.Space [/data/app/com.infoit.nfc.activity -2.apk]
... ...
If I remove the Space element everything is peachy keen. 如果我删除空间元素,一切都是桃子敏锐的。 Somehow it's not able to find the Space class even though I thought defining the xmlns would solve the issue. 不知何故,即使我认为定义xmlns可以解决问题,它也无法找到Space类。 I feel this is something simple, but I am missing it. 我觉得这很简单,但我很想念它。
The xml file needs to refer to existing widgets either defined by the platform or by your own project, and Space
is not a standard Android widget. xml文件需要引用由平台或您自己的项目定义的现有小部件,而Space
不是标准的Android小部件。 Try replacing it with View
instead. 请尝试将其替换为View
。
Space was introduced in API 14 but it's also available from android support v7: 空间是在API 14中引入的,但它也可以从android支持v7获得:
<android.support.v7.widget.Space
android:layout_width="match_parent"
android:layout_height="12dp"/>
By the way: 顺便说说:
dp
instead of px
使用dp
而不是px
android:layout_height
in a vertical LinearLayout
with weight 不需要在垂直LinearLayout
使用权重来修复android:layout_height
The other answers didn't work for me. 其他答案对我不起作用。 Finally, I changed it to v4 like this: 最后,我将其更改为v4,如下所示:
android.support.v4.widget.Space
and it worked fine. 它工作得很好。
Class reference: https://developer.android.com/reference/android/support/v4/widget/Space.html 课程参考: https : //developer.android.com/reference/android/support/v4/widget/Space.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.