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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:11:30+00:00 2026-06-15T06:11:30+00:00

Hi i am new to android development. I am using fragments – but i

  • 0

Hi i am new to android development.

I am using fragments – but i dont entirely understand how it works.

When i launch the app it crashes.

I have googled a lot but cannon solve this 🙁

I have an Activity(MainActivity) that must use a fragment. MainActivity looks like:

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

And the main.xml contains a ListView and a Fragment:

<ListView 
    android:id="@+id/myListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<fragment class="com.todolist.NewItemFragment"
    android:id="@+id/titles_fragment"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

My fragment extends ListFragment and looks like:

public class NewItemFragment extends ListFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.new_item_fragment, container, false);
    }
}

And the new_item_fragment.xml looks like:

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

<ListView 
    android:id="@+id/myListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

I Dont know why it crashes. I must have misunderstood something.
I hope someone out there can help – dont know what to do 🙂

THX


I have imported the library:

android.support.v4.app.FragmentActivity

And made the MainActivity class extend FragmentActivity

It gives me the following error:

enter image description here

  • 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-15T06:11:32+00:00Added an answer on June 15, 2026 at 6:11 am

    Modify the new_item_fragment.xml layout file like this:

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

    to solve the most obvious error. If the app still crashes then post the Logcat with the exception.

    Also, as you’re extending the Activity class make sure you only use the Fragment related classes from the SDK(not the compatibility package if you have it registered in your app). This classes are available starting from Honeycomb.

    If you’re going to use FragmentActivity then make sure you use the Fragment class from the compatibility package(from where the FragmentActivity comes).

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

Sidebar

Related Questions

I am new to android development. Recently I have uploaded an android app using
I am new to Android development. In my project, I’m using EditText, but I
I am new to android development but in the past few weeks I have
I am new in Android app development and using Java language. My problem is
I am new to Android development and facing a problem while using AndEngine. I
I'm new to Mono for Android (using MonoDevelop) and Android development in general. I
I am new to using SQLite databases and android mobile development. I am trying
I am new to Android development. I have both Windows 7 and Mac OS
I am somewhat new to android development and development in general. I have a
I am new to Android development. I am using a x-platform development tool which

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.