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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:07:40+00:00 2026-06-04T06:07:40+00:00

Ok, so I’m trying to use Sherlock to display multiple tabs, each for one

  • 0

Ok, so I’m trying to use Sherlock to display multiple tabs, each for one fragment.
I’ve got only 4classes : one for my main activity, two for my fragments, and one for the TabListener.
Everything should be ok (I’ve got quite the same program without Sherlcock, working on 4.0 devices), so I can’t understand why i get that NullPointerException.

Here’s part of the error

05-18 17:46:57.197: E/AndroidRuntime(9312): FATAL EXCEPTION: main
05-18 17:46:57.197: E/AndroidRuntime(9312): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.micky.testing/com.micky.testing.SherlockTestActivity}: java.lang.NullPointerException
...
05-18 17:46:57.197: E/AndroidRuntime(9312): Caused by: java.lang.NullPointerException
05-18 17:46:57.197: E/AndroidRuntime(9312):     at com.micky.testing.MyTabListener.onTabSelected(MyTabListener.java:21)
...
05-18 17:46:57.197: E/AndroidRuntime(9312):     at com.micky.testing.SherlockTestActivity.onCreate(SherlockTestActivity.java:39)

Here is one of my fragment :
HomeFragment

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;

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

Here is my tabListener :
MyTabListener

public class MyTabListener implements TabListener {

public SherlockFragment fragment;

MyTabListener(SherlockFragment fr) {
    Log.d("MYTAG", "Creating a fragmentListener w/ " + fr);
    this.fragment = fr;
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // TODO Auto-generated method stub
    Log.d("TAG", "" + fragment);
    ft.replace(R.id.fragment_container, fragment);
}

}

And my main activity :
SherlockTestActivity

public class SherlockTestActivity extends SherlockActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //We take the support actionbar
    ActionBar ab = getSupportActionBar();
    //We set to navigationmode with tabs
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //we create the tabs
    ActionBar.Tab homeTab = ab.newTab().setText("Home");
    ActionBar.Tab tagsTab = ab.newTab().setText("Tags");

    //We create the fragments
    SherlockFragment homeFragment = new HomeFragment();
    SherlockFragment tagsFragment = new TagFragments();

    //And we set the tabsListener;
    homeTab.setTabListener(new MyTabListener(homeFragment));
    tagsTab.setTabListener(new MyTabListener(tagsFragment));

    Log.d("","" + homeTab);
    ab.addTab(homeTab);
    ab.addTab(tagsTab);
}

Ok, so the error seems to be thrown when I add the tab to my actionbar. And when I don’t add the TabListener to the tab, there’s no error.
The code ft.replace(R.id.fragment_container, fragment); (MyTabListener) seems to be the problem, but i can’t manage to understand why. fragment isn’t null (initialized when instanciating a new tabListener), and there’s no reason the fragment_container is wrong.

So if anyone can manage to help me around here ! Thank you !

  • 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-04T06:07:42+00:00Added an answer on June 4, 2026 at 6:07 am

    You should be extending SherlockFragmentActivity instead of SherlockActivity. Use a fragment activity when you are managing fragments.

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

Sidebar

Related Questions

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
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
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

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.