2016-03-26 67 views
0

我正在嘗試創建一個教程應用程序。我得到一個消息,說Android studio導航抽屜 - 預期表情

表達預計

case 2: 
    Activity = new Lesson111(); 
    break; 

注意 - 這是不是我的主要活動的整個代碼。但是,當我改變

case 2: 
    fragment = new Lesson111(); 
    break; 

case 2: 
    Activity = new Lesson111(); 
    break; 

問題開始這裏是我的Main.Activity

public class NavigationActivity extends FragmentActivity { 

    private DrawerLayout mDrawerLayout; 
    ImageView home; 
    Fragment fragment = null; 
    TextView appname; 
    ExpandableListView expListView; 
    HashMap<String, List<String>> listDataChild; 
    ExpandableListAdapter listAdapter; 
    List<String> listDataHeader; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_navigation); 
     home = (ImageView)findViewById(R.id.home); 
     home.setOnClickListener(homeOnclickListener); 
     appname = (TextView)findViewById(R.id.appname); 
     setUpDrawer(); 
    } 

    /** 
    * 
    * Get the names and icons references to build the drawer menu... 
    */ 
    private void setUpDrawer() { 
     mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent)); 
     mDrawerLayout.setDrawerListener(mDrawerListener); 
     expListView = (ExpandableListView) findViewById(R.id.lvExp); 
     prepareListData(); 
     listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); 
     // setting list adapter 
     expListView.setAdapter(listAdapter); 
     fragment = new Lesson1(); 
     getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit(); 
     mDrawerLayout.closeDrawer(expListView); 

     expListView.setOnChildClickListener(new OnChildClickListener() { 
      @Override 
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
       switch (groupPosition) { 
       case 0: 
        switch (childPosition) { 
        case 0: 
         fragment = new Lesson1(); 
         break; 
        case 1: 
         fragment = new Lesson11(); 
         break; 
        case 2: 
         Activity = new Lesson111(); 
         break; 
        default: 
         break; 
        } 
        break; 
+0

你還沒有初始化一個活動變量。試試像Activity activity = new Lesson111(); –

+0

我試過你說的話。但是它說的是不兼容的類型。此外,「活動」灰顯。它也說 - 必需:android.app.Activity發現:com.android.pet.view.Lesson111 –

+0

原因你沒有實際實例化一個活動實例。現在它只是掛在那裏。你想達到什麼目的?請更新您的問題,請更多信息請 –

回答

0

我的問題是由這種反應解決。謝謝

你還沒有初始化一個活動變量。試試像Activity activity = new Lesson111(); - OnurÇevik

+0

[更新]正如我試過的Onur Cevik所說的代碼,我沒有任何錯誤。但是,該片段未顯示在我的導航抽屜中。它看起來像情況2: Activity = new Lesson111(); 休息;不管用。它顯示的代碼沒有錯誤。案例陳述僅僅不適用於課程111。 –