2017-07-20 17 views
0

私はxamarinアンドロイドに左のナビゲーションドロワを実装しようとしていますが、このエラーが発生しています。しかし、私はプロジェクトを実行しています。私はこのエラーが発生しています。android xamarinでアクティビティcomponentinfoを開始できません

Java.Lang.RuntimeException: Unable to start activity ComponentInfo{projectName/md513ea1ea7951e2b6363d1a303343de4a9.MainActivity}: java.lang.IllegalStateException: No activity 

は、ここで私はこのエラーが発生した理由はわかりません、私の主な活動

 public class MainActivity : AppCompatActivity 
     { 
      DrawerLayout drawerLayout; 
      NavigationView navigationView; 
      protected override void OnCreate(Bundle bundle) 
      { 
       base.OnCreate(bundle); 
       // Set our view from the "main" layout resource 
       try 
       { 
        SetContentView(Resource.Layout.Main); 
        var toolbar = FindViewById<V7Toolbar>(Resource.Id.toolbar); 
        SetSupportActionBar(toolbar); 
        SupportActionBar.SetDisplayHomeAsUpEnabled(true); 
        SupportActionBar.SetDisplayShowTitleEnabled(false); 
        SupportActionBar.SetHomeButtonEnabled(true); 
        SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu); 
        // Get our button from the layout resource, 
        // and attach an event to it 
        drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout); 
        navigationView = FindViewById<NavigationView>(Resource.Id.nav_view); 
        if (navigationView != null) 
         setupDrawerContent(navigationView); 
       } 

       catch(Exception e) 

       { 
        Console.Write("Erorr:" + e.InnerException); 
       } 
      } 

      public override bool OnOptionsItemSelected(IMenuItem item) 
      { 
       switch (item.ItemId) 
       { 
        case Android.Resource.Id.Home: 
         drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.Start); 
         return true; 
       } 
       return base.OnOptionsItemSelected(item); 
      } 

      void setupDrawerContent(NavigationView navigationView) 
      { 
       navigationView.NavigationItemSelected += (sender, e) => { 
        e.MenuItem.SetChecked(true); 
        drawerLayout.CloseDrawers(); 
       }; 
      } 

} 

です。任意のヘルプは本当に感謝します。

+0

することができます私は、彼らが引き出し()のために独自の活動を作成し、このsample code.

で簡単に見てとることをお勧めしたいですログを投稿する – Raghavendra

答えて

0

ほとんどの場合、IllegalStateExceptionは、「メソッドが不正または不適切な時間に呼び出された」ことを示すために使用されます。

私は、例外を引き起こす可能性が高い描画レイアウトを見つけることがポイントだと思います。

[Activity (Label = "@string/app_name", Icon = "@drawable/ic_launcher")] 
public class NavigationDrawerActivity : Activity, PlanetAdapter.OnItemClickListener 
{ 
    private DrawerLayout mDrawerLayout; 
    private RecyclerView mDrawerList; 
    private ActionBarDrawerToggle mDrawerToggle; 
    private string mDrawerTitle; 
    private String[] mPlanetTitles; 

    protected override void OnCreate (Bundle savedInstanceState) 
    { 

     base.OnCreate (savedInstanceState); 
     SetContentView (Resource.Layout.activity_navigation_drawer); 

     mDrawerTitle = this.Title; 
     mPlanetTitles = this.Resources.GetStringArray (Resource.Array.planets_array); 
     mDrawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout); 
     mDrawerList = FindViewById<RecyclerView> (Resource.Id.left_drawer); 

     // set a custom shadow that overlays the main content when the drawer opens 
     mDrawerLayout.SetDrawerShadow (Resource.Drawable.drawer_shadow, GravityCompat.Start); 
     // improve performance by indicating the list if fixed size. 
     mDrawerList.HasFixedSize = true; 
     mDrawerList.SetLayoutManager (new LinearLayoutManager (this)); 

     // set up the drawer's list view with items and click listener 
     mDrawerList.SetAdapter (new PlanetAdapter (mPlanetTitles, this)); 
     // enable ActionBar app icon to behave as action to toggle nav drawer 
     this.ActionBar.SetDisplayHomeAsUpEnabled (true); 
     this.ActionBar.SetHomeButtonEnabled (true); 

     // ActionBarDrawerToggle ties together the the proper interactions 
     // between the sliding drawer and the action bar app icon 

     mDrawerToggle = new MyActionBarDrawerToggle (this, mDrawerLayout, 
      Resource.Drawable.ic_drawer, 
      Resource.String.drawer_open, 
      Resource.String.drawer_close); 

     mDrawerLayout.SetDrawerListener (mDrawerToggle); 
     if (savedInstanceState == null) //first launch 
      selectItem (0); 
    } 
} 

、その後、彼らは彼らの主な活動からそれを呼び出す:

[Activity (Label = "@string/app_name", MainLauncher = true)]    
public class MainActivity : Activity, AdapterView.IOnItemClickListener 
{ 
    internal Sample[] mSamples; 
    internal GridView mGridView; 

    protected override void OnCreate (Bundle savedInstanceState) 
    { 
     base.OnCreate (savedInstanceState); 
     SetContentView (Resource.Layout.activity_main); 

     // Prepare list of samples in this dashboard. 
     mSamples = new Sample[] { 
      new Sample (Resource.String.navigationdraweractivity_title, 
       Resource.String.navigationdraweractivity_description, 
       this, 
       typeof(NavigationDrawerActivity)), 
     }; 

     // Prepare the GridView 
     mGridView = FindViewById<GridView> (Android.Resource.Id.List); 
     mGridView.Adapter = new SampleAdapter (this); 
     mGridView.OnItemClickListener = this; 
    } 

    public void OnItemClick (AdapterView container, View view, int position, long id) 
    { 
     StartActivity (mSamples [position].intent); 
    } 
} 
関連する問題