簡體   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