Android错误膨胀android.widget.spinner

时间:2014-01-28 09:26:45

标签: android layout spinner

我的布局中有Spinner

     <Spinner
        android:id="@+id/city_spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:entryValues="@array/city_spinner_data"
        />   

当此文件传递给inflater实例时,它会给我这个错误:

01-28 15:00:13.270: D/AndroidRuntime(6100): Shutting down VM
01-28 15:00:13.270: W/dalvikvm(6100): threadid=1: thread exiting with uncaught exception (group=0xa4ba0648)
01-28 15:00:13.270: E/AndroidRuntime(6100): FATAL EXCEPTION: main
01-28 15:00:13.270: E/AndroidRuntime(6100): android.view.InflateException: Binary XML file line #97: Error inflating class android.widget.Spinner
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at in.coupondunia.androidapp.fragments.local.RestaurantOffersHomeFragment.onCreateView(RestaurantOffersHomeFragment.java:26)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.os.Handler.handleCallback(Handler.java:730)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.os.Looper.loop(Looper.java:137)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.app.ActivityThread.main(ActivityThread.java:5103)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at java.lang.reflect.Method.invokeNative(Native Method)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at java.lang.reflect.Method.invoke(Method.java:525)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at dalvik.system.NativeStart.main(Native Method)
01-28 15:00:13.270: E/AndroidRuntime(6100): Caused by: java.lang.reflect.InvocationTargetException
01-28 15:00:13.270: E/AndroidRuntime(6100):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
01-28 15:00:13.270: E/AndroidRuntime(6100):     ... 25 more
01-28 15:00:13.270: E/AndroidRuntime(6100): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0c0084 a=1 r=0x7f0c0084}
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.content.res.Resources.loadDrawable(Resources.java:2063)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.PopupWindow.<init>(PopupWindow.java:187)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.ListPopupWindow.<init>(ListPopupWindow.java:199)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.Spinner$DropdownPopup.<init>(Spinner.java:984)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.Spinner.<init>(Spinner.java:176)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.Spinner.<init>(Spinner.java:139)
01-28 15:00:13.270: E/AndroidRuntime(6100):     at android.widget.Spinner.<init>(Spinner.java:123)
01-28 15:00:13.270: E/AndroidRuntime(6100):     ... 28 more

我尝试用

创建微调器
        android:entries="@array/city_spinner_data"

但我得到同样的错误。

这是整个布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/reastaurants_home" 
     >

        <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/relativeLayout1"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="81dp" 
        android:scrollbars="none"
        >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="5dp"
                android:src="@drawable/flipkart" />

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:src="@drawable/dominos" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:src="@drawable/flipkart" />

        </LinearLayout>
    </HorizontalScrollView>



    <ImageView
        android:id="@+id/dotted_separator"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/relativeLayout1"
        android:layout_marginTop="17dp"
        android:paddingLeft="25dp"
        android:paddingRight="25dp"
        android:src="@drawable/dotted_separator" />

        <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:padding="30dp" >

        <LinearLayout 
            android:id="@+id/title_holder"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
             <TextView
                android:id="@+id/find_restaurant_coupons"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:text="Find Restaurant Coupons"
                android:textColor="#ffffff"
                android:textSize="15sp" />

        </LinearLayout>

        <LinearLayout 
            android:id="@+id/spinner_holder"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/title_holder"
            >
<!--
                android:entries="@array/city_spinner_data"
                -->
             <Spinner
                android:id="@+id/city_spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawSelectorOnTop="true"
                android:entryValues="@array/city_spinner_data"
                />   
        </LinearLayout>

        <LinearLayout 
            android:id="@+id/location_search_holder"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/spinner_holder"
            >
            <EditText
                android:id="@+id/input_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#ffffff"
                android:ems="10"
                android:hint="Location"
                android:inputType="text"
                android:padding="10dp"
                android:textColor="#000000" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/button_go"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/input_location"
                android:background="#17b851"
                android:padding="10dp"
                android:text="GO" />

        </LinearLayout>
    </RelativeLayout>

        <Button
            android:id="@+id/best_restaurants_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/horizontalScrollView1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:background="#17b851"
            android:paddingLeft="25dp"
            android:paddingRight="25dp"
            android:text="Best Restaurants Offers" />

</RelativeLayout>

这是数组:

<string-array name="city_spinner_data">
    <item>Mumbai</item>
    <item>Pune</item>
    <item>Goa</item>
</string-array>

1 个答案:

答案 0 :(得分:0)

android:条目应该有用。

我们也可以设置相同的代码。

Spinner spinner = (Spinner) findViewById(R.id.city_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.city_spinner_data, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);