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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:41:41+00:00 2026-06-08T15:41:41+00:00

I don’t get my fragment to work… :-( My Activity: public class Test extends

  • 0

I don’t get my fragment to work… 🙁

My Activity:

public class Test extends SherlockActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setTitle(R.string.title);
//      actionBar.setDisplayShowTitleEnabled(false);
//

    actionBar.setDisplayShowHomeEnabled(false);



    Tab tab = actionBar.newTab().setText(dayName(Calendar.MONDAY))
            .setTabListener(new WeekDayTabListener(getApplicationContext()));
    actionBar.addTab(tab);

    ...

    tab = actionBar.newTab().setText(dayName(Calendar.SUNDAY))
            .setTabListener(new WeekDayTabListener(getApplicationContext()));
    actionBar.addTab(tab);
}



public static class WeekDayTabListener implements TabListener {

    private Context context;

    public WeekDayTabListener(Context context) {
        this.context = context;
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        Tools.longToast(tab.getText().toString(), this.context);
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

}

}

my xml:

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

   <fragment
        android:id="@+id/weekDayFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        class="com.test.fragment.DayFragment" >
    </fragment>

</LinearLayout>

and finally my Fragment:

import com.actionbarsherlock.app.SherlockFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DayFragment extends SherlockFragment { 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        Context c = getActivity().getApplicationContext();
        LinearLayout l = new LinearLayout(c);
        TextView tv = new TextView(c);
        tv.setText("foo");
        l.addView(tv);

        return l;
    }
}

If I execute, I get the following exception:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.fragment/com.test.fragment.Test}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

So if i comment out the parte there is no error – but the path is correct, so what am i doing wrong?

  • 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-08T15:41:43+00:00Added an answer on June 8, 2026 at 3:41 pm

    Your class Test needs to extend SherlockFragmentActivity not SherlockActivity:

    class Test extends SherlockFragmentActivity{
        ...    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't know how to explain it better but i'm trying to get a response
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
Don't these two mean the same thing, first get the value and then increment?
Don't ask me how but I managed to get accidentally the following remote branches
Don't get me wrong, I want them to get saved. But I always thought
Don't get me wrong - I love Smalltalk, but... To me, the Squeak interface
don't know better title for this, but here's my code. I have class user

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.