0

In my apps class ProjectFragActivtiy encountered exception like

java.lang.ClassCastException: com.actionbarsherlock.internal.view.menu.MenuBuilder 
at com.oj.bs.ProjectFragActivity.onCreateOptionsMenu
(ProjectFragActivity.java:49).

in apps menu button is used for logout operation but encountered exception. Is there another way to implement the menu in actionbarsherlock. Does anyone have a solution to this? Thanks in advance.

following is the ProjectFragActivtiy class

    package com.oj.bs;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;

public class ProjectFragActivity extends SherlockFragmentActivity {

    SessionManager sessionMngr ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        sessionMngr = new SessionManager(getApplicationContext());

        Toast.makeText(getApplicationContext(), "User Login Status: " + sessionMngr .isLoggedIn(), 
                Toast.LENGTH_LONG).show();
        sessionMngr.checkLogin();

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

        Tab tab = actionBar.newTab().
                setText("Residential").
                setTabListener(new ResidentialFragActivity()).
                setIcon(R.drawable.residential);
        actionBar.addTab(tab);

        tab = actionBar.newTab().
              setText("Commercial").
              setTabListener(new  CommercialFragActivity()).
              setIcon(R.drawable.commercial);

        actionBar.addTab(tab);

    }
    public void Logout(View v) {
        sessionMngr.logoutUser();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu m) {
        getMenuInflater().inflate(R.menu.menu_logout, (android.view.Menu) m);
        return true;
    }

}
Nilesh
  • 93
  • 1
  • 2
  • 7

1 Answers1

1

Change the onCreateOptionsMenu() as follows

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
   inflater.inflate(R.menu.menu_logout, (com.actionbarsherlock.view.Menu) menu);
   return true;
}

NOTE :

In order to inflate your menu from XML you should call getSupportMenuInflater() in your activities. The fragment callbacks will already have an instance of the inflater as an argument.

Sankar V
  • 4,794
  • 3
  • 38
  • 56
  • Mr.Shankar I integrate above code but encountered exception like android.view.InflateException: Couldn't resolve menu item onClick handler Logout in class com.ojaswitech.bookinscape.ProjectFragActivity .can you help me. – Nilesh Apr 17 '13 at 09:33
  • check my updated ans and have a look into this link http://stackoverflow.com/q/11245829/1329126 – Sankar V Apr 17 '13 at 09:39