2016-03-26 17 views
0

私はチュートリアルアプリを作成しようとしています。これは私の主な活動の全体のコードではありません - 私はノート Androidスタジオナビゲーションドロワー - 表現が必要

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

式が

を期待というメッセージを取得しています。しかし、問題は、私はここで

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

case 2: 
    fragment = 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 Found:com.android.pet.view.Lesson111 –

+0

実際にアクティビティインスタンスをインスタンス化していないためです。今はちょうどそこにぶら下がっています。あなたは何を達成しようとしていますか?詳細をあなたの質問を更新してください –

答えて

0

私の問題は、この応答により解決しました。ありがとうございました

アクティビティ変数が初期化されていません。 Activity activity = new Lesson111();のようなものを試してみてください。 - OnurÇevik

+0

[更新] Onur Cevikが言ったコードを試したので、もうエラーはありません。しかし、その断片はナビゲーション・ドロワーに表示されません。ケース2のように見えます: アクティビティ= new Lesson111(); 休憩。動かない。コードに表示されるエラーはありません。 case文は、Lesson111では機能しません。 –

関連する問題