1

我正在尝试研究如何开发我的第一个应用程序,但是当我尝试编译此代码时,eclipse 返回错误“构造函数意图未定义”:

package com.baruckis.SlidingMenuImplementation.FromClass;
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.baruckis.SlidingMenuImplementation.R;
import com.baruckis.SlidingMenuImplementation.SlidingMenuListItem;
import com.baruckis.SlidingMenuImplementation.prova;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

public class SlidingMenuBuilderBase {
    protected Activity activity;
protected SlidingMenu menu = null;

public void createSlidingMenu(Activity activity) {
    this.activity = activity;
    menu = new SlidingMenu(activity);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.sliding_menu_shadow_width);
    menu.setShadowDrawable(R.drawable.sliding_menu_shadow);
    menu.setBehindOffsetRes(R.dimen.sliding_menu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(activity, SlidingMenu.SLIDING_WINDOW);
    menu.setMenu(R.layout.sliding_menu_frame);

    SlidingMenuListFragment slidingMenuListFragment = new SlidingMenuListFragment();
    slidingMenuListFragment.setMenuBuilder(this);


    activity.getFragmentManager().beginTransaction()
            .replace(R.id.sliding_menu_frame, slidingMenuListFragment)
            .commit();
}

public SlidingMenu getSlidingMenu() {
    return menu;
}


public void onListItemClick(SlidingMenuListItem selectedSlidingMenuListItem) {
    CharSequence text;
    switch (selectedSlidingMenuListItem.Id) {
    case R.slidingmenu.list_item_municipio_id:
    Intent ii = new Intent(this, prova.class);
    startActivity(ii);
    finish();

        break;
    case R.slidingmenu.list_item_basic_id:
        text = "Clicked item “"
                + selectedSlidingMenuListItem.Name
                + "”. "
                + activity
                        .getString(R.string.toast_sliding_menu_custom_action);
        Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
        break;
    default:
        text = "Clicked item. "
                + activity
                        .getString(R.string.toast_sliding_menu_no_action_default);
        Toast.makeText(activity, text, Toast.LENGTH_LONG).show();
        break;
    }
}

}

我已经尝试在其他线程中寻找解决方案,但我没有找到适合我的方法!

4

2 回答 2

2

改变

Intent ii = new Intent(this, prova.class);

Intent ii = new Intent(activity, prova.class);

你需要一个Activity Context来启动Activity并且因为你的类没有扩展Activity你需要使用activity你传递给它的参数

于 2013-07-02T20:37:16.493 回答
1

那是因为SlidingMenuBuilderBaseis not a Context,like Activityis。由于您在数据成员中保留了一个Activity实例,因此您可以在构造函数中替换为.activitythisIntentactivity

于 2013-07-02T20:36:22.683 回答