2013-07-02 40 views
1

我想學習如何開發我的第一個應用程序,但日食返回我的錯誤 「構造意圖是未定義」當我嘗試編譯此代碼:錯誤:構造意圖是不確定的

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

}

我已經試過尋找其他線程的解決方案,但我沒有找到一種方法爲我工作!

回答

2

變化

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

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

你需要一個Activity Context啓動Activity既然你的類不會擴展Activity您需要使用您傳遞給它的

參數 activity
+0

優秀!它適用於我,謝謝:) – Peppegiuseppe

1

那是因爲SlidingMenuBuilderBase不是Context,就像Activity一樣。由於您正在使用activity數據成員中的Activity實例,因此可以用activity替代Intent構造函數中的this