Android Emulator Force closes when loading Custom Layout
I created a custom layout where I have a couple of LinearLayout in a ScrollView. Problem is when I set my layout in setContentView()
to my custom layout (when the application starts), the emulator gives an error and force closes! I don't know why. I have tried with another custom layout or set it to main and it seems to work fine.
Any ideas what could be wrong?
Yes, I meant to say the app is crashing. Here is the xml code for the custom layout: (too many spinners!)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<开发者_开发技巧TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Name"
android:id="@+id/name"
android:textSize="18sp"
android:gravity="center">
</TextView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Picker"
android:text="@string/drinkText"
android:textColor="#303030">
</TextView>
<View
android:layout_height="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TimePicker"
android:text="@string/TimeText"
android:textColor="#303030">
</TextView>
<View
android:layout_height="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/EndPicker"
android:text="@string/EndText"
android:textColor="#303030">
</TextView>
<View
android:layout_height="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/sortPicker"
android:text="@string/sortText"
android:textColor="#303030">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categories:"
android:id="@+id/CategorySelect"/>
<Spinner
android:id="@+id/categorySpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/categoriesPrompt"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Priority:"
android:id="@+id/prioritySelect"/>
<Spinner
android:id="@+id/prioritySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/priorityPrompt"
android:visibility="visible" android:layout_weight="0.0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="State:"
android:id="@+id/stateSelect"/>
<Spinner
android:id="@+id/statusSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/statusPrompt"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reminder:"
android:id="@+id/Reminder"/>
<Spinner
android:id="@+id/remindSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/remindPrompt"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#FF303030">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="suggestions:"
android:typeface="sans">
</TextView>
</LinearLayout>
</LinearLayout>
</ScrollView>
The problem is that you're specifying a view without including a required attribute (layout_width
).
<View android:layout_height="5dp"/>
It's up to you to define the expected behavior for width, but here's one example that will fix your problem:
<View android:layout_height="5dp" layout_width="fill_parent" />
The Android developer documentation indicates these fields are required (source: http://developer.android.com/guide/topics/resources/layout-resource.html).
精彩评论