Christian Christian -4 years ago 123
Android Question

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:

<?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): 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): Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class Space

...

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]

...




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. I feel this is something simple, but I am missing it.

Answer Source

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. Try replacing it with View instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download