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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:28:10+00:00 2026-06-12T09:28:10+00:00

I got an error while trying to run my app. Could anyone please help

  • 0

I got an error while trying to run my app. Could anyone please help me check on my codes? I will list out all my codes. I’m trying to implement fragments to my app.

MainActivity.java

public class MainActivity extends SherlockFragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

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

        actionBar.setDisplayShowTitleEnabled(true);

        Tab tab = actionBar.newTab()
                .setText("Apple")
                .setTabListener((TabListener) new AppleFragment())
                .setIcon(R.drawable.apple);

        actionBar.addTab(tab);


    }  

}

AppleFragment.java

public class AppleFragment extends ListActivity  {

    static final String URL = "http://api.androidhive.info/pizza/?format=xml";
    // XML node keys
    static final String KEY_ITEM = "item"; // parent node
    static final String KEY_ID = "id";
    static final String KEY_NAME = "name";
    static final String KEY_COST = "cost";
    static final String KEY_DESC = "description";

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

    ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();


    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_ITEM);
    // looping through all item nodes <item>
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);
        // adding each child node to HashMap key => value
        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
        map.put(KEY_COST, "Rs." + parser.getValue(e, KEY_COST));
        map.put(KEY_DESC, parser.getValue(e, KEY_DESC));

        // adding HashList to ArrayList
        menuItems.add(map);
    }

    ListAdapter adapter = new SimpleAdapter(this, menuItems,
            R.layout.list_item,
            new String[] { KEY_NAME, KEY_DESC, KEY_COST }, new int[] {
                    R.id.name, R.id.desciption, R.id.cost });


    setListAdapter(adapter);



}

    public static class ArrayListFragment extends SherlockListFragment implements TabListener{


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){




        return super.onCreateView(inflater, container, savedInstanceState);


    }    


    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        ft.add(android.R.id.content, this);

        ft.attach(this);
    }

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

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

}
}

Logcat :

10-04 16:55:52.805: E/AndroidRuntime(26238): FATAL EXCEPTION: main
10-04 16:55:52.805: E/AndroidRuntime(26238): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.actionbarsherlocknavtab/in.wptrafficanalyzer.actionbarsherlocknavtab.MainActivity}: java.lang.ClassCastException: in.wptrafficanalyzer.actionbarsherlocknavtab.AppleFragment cannot be cast to com.actionbarsherlock.app.ActionBar$TabListener
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.os.Looper.loop(Looper.java:137)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread.main(ActivityThread.java:4512)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at java.lang.reflect.Method.invokeNative(Native Method)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at java.lang.reflect.Method.invoke(Method.java:511)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at dalvik.system.NativeStart.main(Native Method)
10-04 16:55:52.805: E/AndroidRuntime(26238): Caused by: java.lang.ClassCastException: in.wptrafficanalyzer.actionbarsherlocknavtab.AppleFragment cannot be cast to com.actionbarsherlock.app.ActionBar$TabListener
10-04 16:55:52.805: E/AndroidRuntime(26238):    at in.wptrafficanalyzer.actionbarsherlocknavtab.MainActivity.onCreate(MainActivity.java:30)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.Activity.performCreate(Activity.java:4465)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
10-04 16:55:52.805: E/AndroidRuntime(26238):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
10-04 16:55:52.805: E/AndroidRuntime(26238):    ... 11 more
  • 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-12T09:28:11+00:00Added an answer on June 12, 2026 at 9:28 am

    The error is in:

    Tab tab = actionBar.newTab()
                    .setText("Apple")
                    .setTabListener((TabListener) new AppleFragment())
                    .setIcon(R.drawable.apple);
    

    the tab listener cannot be new AppleFragment() you should pass a valid listener, or make your fragment implements TabListener

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

Sidebar

Related Questions

Got these error while trying to run my first Java webservice tutorial in Eclipse.
i got this error while trying to rebind a grid: ( Parent page (
Got this error message while trying to load view: The model item passed into
Got this error message while trying to configure an entitydatasource in the designer: My
I got the following error while trying to alter a column's data type and
got error when i try to run WebService in Debug this error: error while
While i am trying to get value from arraylist,i got the following errors.My sample
I got the following error while running my perl script with the negative lookaround
I got this error An error occurred while parsing EntityName. Line 1, position 61.
i got 'JQuery' is undefined error while browsing the page in IE 6 but

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.