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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:47:09+00:00 2026-06-11T15:47:09+00:00

I shall try my best to post the relevant code and explain clearly… I’m

  • 0

I shall try my best to post the relevant code and explain clearly… I’m following a tutorial on Android; it was a ListView Application which I am now converting to fragments. It told me to change one of my classes from extends ListActivity to extends Activity. In doing so, two of my calls particular to ListActivity needed changing. I thought I changed them properly, but I am getting these errors (just the top of the list):

W/dalvikvm(4486): threadid=1: thread exiting with uncaught exception (group=0x40209760)
E/AndroidRuntime(4486): FATAL EXCEPTION: main
E/AndroidRuntime(4486): java.lang.RuntimeException: Unable to start activity 
    ComponentInfo{com.example.testing/com.example.testing.MainActivity}:
    java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.widget.ListView

My main activity code, the part I believe relevant, is:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_fragment);

    ListView lv = (ListView) findViewById(R.id.list_fragment);
    lv.setAdapter(ArrayAdapter.createFromResource(getApplicationContext(),
            R.array.tut_titles, R.layout.activity_main));
    final String[] links = getResources().getStringArray(R.array.tut_links);

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick......

        }
    });
}

The lv variable is new, and the two calls made with it used to be ListActivity specific. My list_fragment is merely this so far:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:name="com.example.testing.UrlFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/list_fragment">
</fragment>

Phew! I think that’s all that’s needed, but if I knew for certain, I could probably fix this myself. Can anyone help?

  • 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-11T15:47:10+00:00Added an answer on June 11, 2026 at 3:47 pm

    You have a problem in following line.

    ListView lv = (ListView) findViewById(R.id.list_fragment);
    

    From R file you are referencing fragment but you are going to cast it to ListView that is your problem.you can simply solve it as follows.

    1) create a class extending Fragment.

    public static class YourFragmentClass extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.example_fragment, container, false);
        }
    }
    

    2) In your activity class.

    YourFragmentClass fragment = new YourFragmentClass ();
    fragmentTransaction.add(R.id.list_fragmentr, fragment);
    fragmentTransaction.commit();
    

    3) for more check this out

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

Sidebar

Related Questions

Hi I shall try to explain clearly what I need to be able to
This is such a difficult question to explain online but I shall try my
I will try to explain this the best way I can, but feel free
I'll try to explain the problem we have at my company the best I
This is a little complicated so I will try and explain as best as
Im working on a small application to try out an idea that I have.
i am try to develop a small application. Now should i organize my 3rd
from my small knowlegde from java se i want to try a tutorial on
I have developed a small application that I would like to try and sell
I'm working on a small application from scratch and using it to try to

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.