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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:58:07+00:00 2026-06-06T14:58:07+00:00

I get this error message in LogCat: 06-25 15:17:34.495: E/AndroidRuntime(5891): java.lang.RuntimeException: Unable to start

  • 0

I get this error message in LogCat:

06-25 15:17:34.495: E/AndroidRuntime(5891):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example/com.example.MainActivity}:
java.lang.NullPointerException
06-25 16:07:43.589: E/AndroidRuntime(6587): Caused by: java.lang.NullPointerException
06-25 16:07:43.589: E/AndroidRuntime(6587): at com.example.MyTabsListener.onTabSelected(MyTabListener.java:28)

This is my main activity:

package com.example;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;

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

        ActionBar actionbar = getSupportActionBar();
        actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab tab1 = actionbar.newTab().setText("Fragment A");
        SherlockFragment fragment1 = new AFragment();

        tab1.setTabListener(new MyTabsListener(fragment1, this
            .getApplicationContext()));
        actionbar.addTab(tab1);
    }

}

And my simple TabListener:

package com.example;    

import android.content.Context;
import android.support.v4.app.FragmentTransaction;
import android.widget.Toast;  

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragment;

class MyTabsListener implements ActionBar.TabListener {
    public SherlockFragment fragment;
    private final Context appContext;

    public MyTabsListener(SherlockFragment fragment, Context ctx) {
        this.fragment = fragment;
        this.appContext = ctx;
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        Toast.makeText(this.appContext, "Reselected!", Toast.LENGTH_LONG)
                .show();
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.replace(R.id.fragment_container, fragment);
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        ft.remove(fragment);
    }
}

And finally my class Fragment A:

package com.example;

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

import com.actionbarsherlock.app.SherlockFragment;

public class AFragment extends SherlockFragment {

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

}

So this function is causing the error in the TabListener:

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
  ft.replace(R.id.fragment_container, fragment);
}
  • 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-06T14:58:07+00:00Added an answer on June 6, 2026 at 2:58 pm
    1. MainActivity has to extend SherlockFragmentActivity (credits to JosipPranjic!).
    2. The NullPointerException can be fixed with following code from this SO question: Null FragmentTransaction being passed to TabListener.onTabSelected()

      @Override
      public void onTabSelected(Tab tab, FragmentTransaction ignoredFt) {
        FragmentManager fragMgr = ((FragmentActivity) mActivity)
              .getSupportFragmentManager();
        FragmentTransaction ft = fragMgr.beginTransaction();
      
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
      
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            // If it exists, simply attach it in order to show it
            ft.attach(mFragment);
        }
      
        ft.commit();
      }
      
      @Override
      public void onTabUnselected(Tab tab, FragmentTransaction ignoredFt) {
        FragmentManager fragMgr = ((FragmentActivity) mActivity)
                .getSupportFragmentManager();
        FragmentTransaction ft = fragMgr.beginTransaction();
      
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
      
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            // If it exists, simply attach it in order to show it
            ft.detach(mFragment);
        }
      
        ft.commit();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error message as I execute my JUnit tests: java.lang.OutOfMemoryError: GC overhead
I'm using websphere and Java EE and get this error message: Exception reading propertiesfile
I get this error message when I try to use mysql_fetch_array(): while( $deffefgpSfet->fetch() )
I get this error message in Visual Studio when I'm trying to run the
I get this error message when i use URL Linter with my website http://developers.facebook.com/tools/debug/og/object?q=iulianonofrei.com
I get this error message in Eclipse: Access restriction: The type DirectoryWalker is not
I get this error message from a Ghostscript call: Error: /syntaxerror in -file- Operand
Sometimes I get this error message from time-based trigger of many scripts ... There
Why do I get this error message with this code? Use of undeclared identifier
When invoking a query on the data service I get this error message inside

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.