Reputation: 799
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.
Upvotes: 10
Views: 9550
Reputation: 294
Using the View
component in place of Space
might work.
But I would try to keep Space
, but using the following:
<android.widget.Space …>
It tends to work more reliably than when it worked with <Space …>
.
Another option is using the legacy version:
<androidx.legacy.widget.Space …>
Upvotes: 15
Reputation: 623
The other answers didn't work for me. Finally, I changed it to v4 like this:
android.support.v4.widget.Space
and it worked fine.
Class reference: https://developer.android.com/reference/android/support/v4/widget/Space.html
Upvotes: 2
Reputation: 11177
Space was introduced in API 14 but it's also available from android support v7:
<android.support.v7.widget.Space
android:layout_width="match_parent"
android:layout_height="12dp"/>
By the way:
dp
instead of px
android:layout_height
in a vertical LinearLayout
with weightUpvotes: 7
Reputation: 14700
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.
Upvotes: 13