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

  • Home
  • SEARCH
  • 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 7884801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:53:57+00:00 2026-06-03T04:53:57+00:00

I’m trying to run an example I found it on a book about the

  • 0

I’m trying to run an example I found it on a book about the ListView. As the book stated, I created the string-array in string.xml file and the layout of the ListView is in list_item.xml inside res->layout folder.

The problem is that, the app crashes when I run the activity. Can any one tell me where the mistake is?

Code1:

public class ListViewTestActivity extends ListActivity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] c = getResources().getStringArray(R.array.cities);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, c));
    }}

string.xml

<resources>

<string name="hello">Hello World, ListViewTestActivity!</string>
<string name="app_name">ListViewTest</string>

<string-array
        name="cities">
    <item>Bath</item>
    <item>Birmingham</item>
    <item>Bradford</item>
    <item>Brighton</item>
    <item>Bristol</item>
    <item>Cambridge</item>
    <item>Canterbury</item>
</string-array>

list_item.xml:

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

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="28dip">
    </TextView>


</LinearLayout>

LogCat:

    05-05 22:45:16.018: E/ArrayAdapter(648): You must supply a resource ID for a TextView
05-05 22:45:16.048: E/AndroidRuntime(648): FATAL EXCEPTION: main
05-05 22:45:16.048: E/AndroidRuntime(648): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ListView.fillDown(ListView.java:670)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ListView.fillFromTop(ListView.java:727)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ListView.layoutChildren(ListView.java:1598)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.View.layout(View.java:7175)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.View.layout(View.java:7175)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.View.layout(View.java:7175)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.View.layout(View.java:7175)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.os.Looper.loop(Looper.java:130)
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.app.ActivityThread.main(ActivityThread.java:3683)
05-05 22:45:16.048: E/AndroidRuntime(648):  at java.lang.reflect.Method.invokeNative(Native Method)
05-05 22:45:16.048: E/AndroidRuntime(648):  at java.lang.reflect.Method.invoke(Method.java:507)
05-05 22:45:16.048: E/AndroidRuntime(648):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-05 22:45:16.048: E/AndroidRuntime(648):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-05 22:45:16.048: E/AndroidRuntime(648):  at dalvik.system.NativeStart.main(Native Method)
05-05 22:45:16.048: E/AndroidRuntime(648): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
05-05 22:45:16.048: E/AndroidRuntime(648):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
  • 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-03T04:53:58+00:00Added an answer on June 3, 2026 at 4:53 am

    If you use that particular layout for the row item then assign an id to the TextView and pass that in the constructor of the adapter to let the adapter know where to place the data:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <TextView
        android:id="@+id/text"  
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="28dip">
    </TextView>
    

    and in your activity:

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.text, c));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.