繁体   English   中英

运行应用程序时android.view.Space的ClassNotFoundException

[英]ClassNotFoundException for android.view.Space when running application

当我的活动布局中存在某些元素时,我遇到运行应用程序的问题。 我有以下布局,当我包含“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>

我得到的错误是这样的:

11-26 11:14:09.875:E / AndroidRuntime(10485):致命异常:主要
...
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:loader dalvik.system.PathClassLoader中的android.view.Space [/data/app/com.infoit.nfc.activity -2.apk]
...

如果我删除空间元素,一切都是桃子敏锐的。 不知何故,即使我认为定义xmlns可以解决问题,它也无法找到Space类。 我觉得这很简单,但我很想念它。

xml文件需要引用由平台或您自己的项目定义的现有小部件,而Space不是标准的Android小部件。 请尝试将其替换为View

空间是在API 14中引入的,但它也可以从android支持v7获得:

    <android.support.v7.widget.Space
            android:layout_width="match_parent"
            android:layout_height="12dp"/>

顺便说说:

  • 使用dp而不是px
  • 不需要在垂直LinearLayout使用权重来修复android:layout_height

其他答案对我不起作用。 最后,我将其更改为v4,如下所示:

android.support.v4.widget.Space

它工作得很好。

课程参考: https//developer.android.com/reference/android/support/v4/widget/Space.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM