膨胀Spinner时出错

时间:2013-04-12 09:37:44

标签: android android-spinner

我正在尝试创建一个包含Spinner的UI。这是XML(微调器几乎到最后):

 <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout style="@style/header" >

    <Button
        android:id="@+id/btnBack_profileEdit"
        style="@style/header_button"
        android:layout_gravity="center_vertical"
        android:layout_margin="@dimen/default_button_padding"
        android:background="@drawable/ic_button"
        android:drawableLeft="@drawable/ic_back_arrow"
        android:gravity="right|center_vertical"
        android:text="@string/back"
        android:textColor="@android:color/white"
        android:textSize="@dimen/header_button_text" />

    <TextView
        android:id="@+id/title_profileEdit"
        style="@style/header_text"
        android:singleLine="true"
        android:text="@string/my_profile" />

    <ImageButton
        android:id="@+id/btnSave_profileEdit"
        style="@style/header_button"
        android:src="@drawable/ic_add" />
</LinearLayout>

<LinearLayout
    style="@style/row"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/first_name"
        android:textColor="@color/black_text" />

    <EditText
        android:id="@+id/firstName_profileEdit"
        style="@style/profile_row_edit_text"
        android:imeOptions="actionNext" />
</LinearLayout>

<LinearLayout
    style="@style/row"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/last_name"
        android:textColor="@color/black_text" />

    <EditText
        android:id="@+id/lastName_profileEdit"
        style="@style/profile_row_edit_text"
        android:imeOptions="actionNext" />
</LinearLayout>

<LinearLayout
    style="@style/row"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/email"
        android:textColor="@color/black_text" />

    <EditText
        android:id="@+id/email_profileEdit"
        style="@style/profile_row_edit_text"
        android:imeOptions="actionNext" />
</LinearLayout>

<LinearLayout
    style="@style/row"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/password"
        android:textColor="@color/black_text" />

    <EditText
        android:id="@+id/password_profileEdit"
        style="@style/profile_row_edit_text"
        android:imeOptions="actionNext"
        android:inputType="textPassword" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lytRole_profileEdit"
    style="@style/row"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/role"
        android:textColor="@color/black_text" />

    <Spinner
        android:id="@+id/role_profileEdit"
        android:layout_width="match_parent"
        android:gravity="center_vertical"
        android:layout_height="wrap_content"
        android:layout_weight=".5"
        android:entries="@string/role" />
</LinearLayout>

<LinearLayout
    android:id="@+id/lytSeparator_profileEdit"
    style="@style/separator" >

    <TextView
        style="@style/separator_content"
        android:text="@string/nickname_for_my_profile" />
</LinearLayout>

<LinearLayout
    style="@style/row"
    android:id="@+id/lytNickname_profileEdit"
    android:background="@drawable/white_gradient" >

    <TextView
        style="@style/profile_row_content"
        android:text="@string/nickname"
        android:textColor="@color/black_text" />

    <EditText
        android:id="@+id/nickname_profileEdit"
        style="@style/profile_row_edit_text"
        android:layout_height="wrap_content" />
</LinearLayout>

</LinearLayout>

现在,当我尝试启动活动时,在展开此布局时,应用程序崩溃并且错误是:

Binary XML file line #105: Error inflating class android.widget.Spinner

是什么原因?

1 个答案:

答案 0 :(得分:3)

角色是什么?是<string-array>,然后是

更改此行

 android:entries="@string/role" 

 android:entries="@array/role"