Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

receiving error when inflating spinner layout

Tags:

android

So I am trying to set a custom image for my spinner drop down. I have went to a few stackoverflow questions and they all seem to have the same solution to get it done. For some reason when I try it I get this error java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.plansly/com.example.plansly.planner}: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class Spinner at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) Caused by: android.view.InflateException: Binary XML file line #36: Binary XML file line #36: Error inflating class Spinner Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class Spinner Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.plansly:drawable/ic_spinner_dropdown with resource ID #0x7f07006d Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_spinner_dropdown.xml from drawable resource ID #0x7f07006d at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:837) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:659) at android.content.res.Resources.loadDrawable(Resources.java:900) at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:953) at android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.view.View.<init>(View.java:5078) at android.view.ViewGroup.<init>(ViewGroup.java:597) at android.widget.AdapterView.<init>(AdapterView.java:280) at android.widget.AbsSpinner.<init>(AbsSpinner.java:74) at android.widget.Spinner.<init>(Spinner.java:258) at android.widget.Spinner.<init>(Spinner.java:225) at android.widget.Spinner.<init>(Spinner.java:175) at android.support.v7.widget.AppCompatSpinner.<init>(AppCompatSpinner.java:196) at android.support.v7.widget.AppCompatSpinner.<init>

activity spinner is in:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/activityBackGroundColor"
    tools:context=".planner">
<Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="467dp"
        android:paddingStart="0dp"
        android:spinnerMode="dropdown"
        android:layout_marginRight="30dp"
        android:background="@drawable/ic_spinner_dropdown"
        >
    </Spinner>
</RelativeLayout>

ic_spinner_dropdown drawable file:

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="2.5dp" />
        </shape>
    </item>
    <item android:right="64dp">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/more_vert" />
    </item>
</layer-list>
like image 408
Ike Nwaogu Avatar asked Oct 16 '25 19:10

Ike Nwaogu


1 Answers

I changed the ic_spinner_dropdown drawable and that fixed the problem. from:

`

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="2.5dp" />
        </shape>
    </item>
    <item android:right="64dp">
        <bitmap
            android:gravity="right|center_vertical"
            android:src="@drawable/more_vert" />
    </item>
</layer-list>

to

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:right="64dp"
        android:drawable="@drawable/more_vert"
        android:gravity="left|center_vertical">
    </item>
</layer-list>

In other words delete the bitmap code and and set the drawable source in the item tag and use gravity to set the position of drop down image

like image 97
Ike Nwaogu Avatar answered Oct 19 '25 10:10

Ike Nwaogu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!