Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:44:48+00:00 2026-06-10T19:44:48+00:00

I’ve got an Adapter for a class Area which works for a ListView, but

  • 0

I’ve got an Adapter for a class Area which works for a ListView, but when I want to use this Adapter for a spinner i get an error.
When I’m in the activity with the spinner it shows the first item of the List but when i click the arrow to show the other items too I get an error.
Could someone please tell me what I’m doing wrong?

The Adapter Class:

public class AreaAdapter extends ArrayAdapter<Area> {

    List<Area> areaList;

    public AreaAdapter(Context context, int textViewResouceId,
            List<Area> objects) {
        super(context, textViewResouceId, objects);
        areaList = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            Context c = getContext();
            LayoutInflater inflater = (LayoutInflater) c
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(
                    R.layout.activity_choose_area_adapter, null);
        }

        Area area = areaList.get(position);

        if (area != null) {
            TextView v = null;

            v = (TextView) convertView.findViewById(R.id.tareaname);
            v.setText(area.getAreaName());
        }

        return convertView;
    }
}

XML of the adapter:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.72"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tareaname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

</LinearLayout>

Activity which contains the spinner:

public class ExtrasAddItemActivity extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_extras_add_item);

        ActivitiesObjects ao = (ActivitiesObjects) this.getApplication();
        List<Area> listOfAreas = ao.getListOfAreas();

        Spinner spinnerArea = (Spinner)findViewById(R.id.spinnerExtraArea);
        AreaAdapter areaAdapter = new AreaAdapter(this,R.layout.activity_choose_area_adapter, listOfAreas);
        spinnerArea.setAdapter(areaAdapter);
    }
}

XML with the spinner:

<?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" >

    // other widgets ...

    <Spinner
        android:id="@+id/spinnerExtraArea"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

The error log:

09-05 13:36:05.347: D/dalvikvm(274): GC_EXTERNAL_ALLOC freed 813 objects / 59328 bytes in 54ms
09-05 13:36:10.487: W/KeyCharacterMap(274): No keyboard for id 0
09-05 13:36:10.487: W/KeyCharacterMap(274): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-05 13:36:13.058: E/ArrayAdapter(274): You must supply a resource ID for a TextView
09-05 13:36:13.058: D/AndroidRuntime(274): Shutting down VM
09-05 13:36:13.068: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
09-05 13:36:13.101: E/AndroidRuntime(274): FATAL EXCEPTION: main
09-05 13:36:13.101: E/AndroidRuntime(274): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:329)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:325)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.ListView.onMeasure(ListView.java:1109)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.View.measure(View.java:8171)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.View.measure(View.java:8171)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
09-05 13:36:13.101: E/AndroidRuntime(274):  at com.android.internal.widget.WeightedLinearLayout.onMeasure(WeightedLinearLayout.java:60)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.View.measure(View.java:8171)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.View.measure(View.java:8171)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.View.measure(View.java:8171)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.os.Looper.loop(Looper.java:123)
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 13:36:13.101: E/AndroidRuntime(274):  at java.lang.reflect.Method.invokeNative(Native Method)
09-05 13:36:13.101: E/AndroidRuntime(274):  at java.lang.reflect.Method.invoke(Method.java:521)
09-05 13:36:13.101: E/AndroidRuntime(274):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 13:36:13.101: E/AndroidRuntime(274):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 13:36:13.101: E/AndroidRuntime(274):  at dalvik.system.NativeStart.main(Native Method)
09-05 13:36:13.101: E/AndroidRuntime(274): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
09-05 13:36:13.101: E/AndroidRuntime(274):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
09-05 13:36:13.101: E/AndroidRuntime(274):  ... 34 more

Thanks in advance,
Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:44:50+00:00Added an answer on June 10, 2026 at 7:44 pm

    The problem is that the XML for R.layout.activity_choose_area_adapter is not a text view: the adapter is fine, but Spinner explictly requires that it be a text view, not a complex view. If you want a complex view you have to replicate the Spinner’s behavior yourself. Replace R.layout.activity_choose_area_adapter with something like android.R.layout.simple_list_item_1 and you should be fine.

    Spinner spinnerArea = (Spinner)findViewById(R.id.spinnerExtraArea);
    AreaAdapter areaAdapter = new AreaAdapter(this,android.R.layout.simple_list_item_1, listOfAreas);
    spinnerArea.setAdapter(areaAdapter);
    

    You might also probably need to modify the Adapter to use the passed resource, rather than hardwiring it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.