2016-11-21 164 views
0

我有兩個活動(MainActivity和SeconActivity):了java.lang.RuntimeException和拋出java.lang.ClassNotFoundException

namespace App16 
{ 
    [Activity(Label = "App16", MainLauncher = true, Icon = "@drawable/icon")] 
    public class MainActivity : Activity 
    { 

     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 

      // Set our view from the "main" layout resource 
      SetContentView(Resource.Layout.Main); 

      // Get our button from the layout resource, 
      // and attach an event to it 
      Button button = FindViewById<Button>(Resource.Id.MyButton); 

      button.Click += delegate 
      { 

       var activity2 = new Intent(this, typeof(SecondActivity)).SetFlags(ActivityFlags.ReorderToFront); 
       //var activity2 = new Intent(this, typeof(EnglishWord)); 
       activity2.PutExtra("MyData", "Clicked"); 
       StartActivity(activity2); 
      }; 
     } 
    } 
} 

和:

namespace App16 
{ 
    [Activity(Label = "SecondActivity")] 
    public class SecondActivity : Activity 
    { 
     Button button; 
     protected override void OnCreate(Bundle savedInstanceState) 
     { 
      base.OnCreate(savedInstanceState); 

      SetContentView(Resource.Layout.Main2); 
      //Toast.MakeText(this, "Hello", ToastLength.Short).Show(); 
      string text = Intent.GetStringExtra("MyData") ?? "Data not available"; 
      //string text = Intent.GetStringExtra("MyData"); 
      Toast.MakeText(this, text, ToastLength.Long).Show(); 
      button.Text = text; 
     } 
    } 
} 

和AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App16.App16" android:versionCode="1" android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="16" /> 
    <application android:label="App16"> 
    <activity 
    android:name=".MainActivity" > 
     <intent-filter > 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".SecondActivity" > 
    </activity> 
    </application> 
</manifest> 

我有這個錯誤:

java.lang.runtimeexception: unable to instantiate activity componentInfo {app16.app16/app16.app16.mainactivity}: java.lang.classnotfoundexception: Did not find class "app16.app16.mainactivity" on path:/data/app/app16.app16-1.apk

With android:name="App16.App16.MainActivity"我在模擬器中沒有任何輸出。

+0

這不是c#,不是嗎? – Pikoh

+0

@Pikoh這似乎是C#代碼,但我不確定OP如何獲取與Java相關的錯誤。 – Stijn

+0

這就是爲什麼我問@stijn。我刪除了C#標籤,但現在我不確定(沒有使用Xamarin) – Pikoh

回答

1

不應該包只是App16在這裏?

package="App16.App16" 
+0

我在AndroidManifest中有package =「App16.App16」 – user2111639

+0

是且清單包聲明(= App16.App16)與您的MainActivity的名稱空間不匹配(= App16) –

+0

爲什麼包的名稱是App16.App16? – user2111639

相關問題