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 8629911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:55:44+00:00 2026-06-12T08:55:44+00:00

I got runtime error exception: java.lang.ClassCastException: android.widget.TwoLineListItem cannot be cast to android.widget.TextView My Activity

  • 0

I got runtime error exception:

java.lang.ClassCastException: android.widget.TwoLineListItem cannot be cast to android.widget.TextView

My Activity extends Activity NOT ListActivity and here is my layout construction:

<LinearLayout ...> <ListView ...></ListView> </LinearLayout>

Java:

   ListView lv1 = (ListView) findViewById(R.id.listViewXMLdata);
    ArrayAdapter<String> arrAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2,
        android.R.id.text2, getResources().getStringArray(R.array.countries));

    lv1.setAdapter(arrAdapter);

    lv1.setOnItemClickListener(new OnItemClickListener() {          
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            lView.getItemAtPosition(position);

            String itemSelected = ((TextView) view).getText().toString();
            Toast.makeText(getApplicationContext(), "Clicked Position Number " + position + ": " + itemSelected ,
                    Toast.LENGTH_SHORT)
                    .show();


        }
    });

My only main concern is just to get the string (item selected) on my list.

NOTE 1: I am not working on any database.

NOTE 2: I already tried casting it to CharSequence itemSelected = ((TextView) view).getText().toString() but still got runtime error.

The runtime error occurs only when I started to select item on the list.

  • 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-12T08:55:45+00:00Added an answer on June 12, 2026 at 8:55 am

    The android.R.layout.simple_list_item_2 has as its root a TwoLineListItem widget with two children(two TextViews), the two rows of text. Casting this widget to a TextView will fail with the exception you see in the logcat. Search for the desired TextView with findViewById:

    String itemSelected = ((TextView) view.findViewById(android.R.id.text2)).getText().toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a runtime exception while developing an App. Here is my LogCat.
I got the following error: > org.apache.jasper.JasperException: An > exception occurred processing JSP page
Got these error while trying to run my first Java webservice tutorial in Eclipse.
I'd like to use the Java method: Runtime.getRuntime().availableProcessors() and save the result in a
import java.lang.Process; import java.io.*; import java.io.InuputStream; import java.io.IOException; public class newsmail{ public static void
String command = javac -cp .:../sqljdbc.jar SetHash.java; Process child = Runtime.getRuntime().exec(command); try{ c= child.waitFor();
I got a problem : I try to call a java method that's supposed
Alright, so I created a JavaScript file named HelloWorld.js with the following contents: java.lang.System.out.println(Hello
I am trying to make a curl POST from java through java's Runtime. When
Possible Duplicate: How to make pipes work with Runtime.exec()? Hello i wrote simple java

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.