java.lang.RuntimeException和java.lang.classNotFoundException

时间:2016-11-21 15:14:27

标签: c# android exception

我有两个活动(MainActivity和SeconActivity):

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:无法实例化活动componentInfo {app16.app16 / app16.app16.mainactivity}:java.lang.classnotfoundexception:未找到类&#34; app16.app16.mainactivity&#34;路径:/data/app/app16.app16-1.apk

使用android:name="App16.App16.MainActivity"我在模拟器中没有任何输出。

1 个答案:

答案 0 :(得分:1)

这不应该只是App16吗?

package="App16.App16"