0

在我的应用程序类 ProjectFragActivtiy 遇到异常,如

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

在应用程序菜单按钮用于注销操作但遇到异常。是否有另一种方法来实现 actionbarsherlock 中的菜单。有人对此有解决方案吗?提前致谢。

以下是 ProjectFragActivtiy 类

    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;
    }

}
4

1 回答 1

1

更改onCreateOptionsMenu()如下

@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;
}

笔记 :

为了从 XML 扩充您的菜单,您应该调用getSupportMenuInflater()您的活动。片段回调已经有一个充气器的实例作为参数。

于 2013-04-17T09:02:50.253 回答