我正在尝试创建一个具有按钮的活动,单击另一个活动启动。但是当我在 android AVD 上运行应用程序时,它显示错误“不幸的是,您的应用程序已停止”。
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends Activity implements View.OnClickListener {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(this);
}
public void onClick(View view){
startActivity(new Intent("com.example.myapp.SecondActivity.java"));
}
}
第二个活动具有以下代码:
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
public class SecondActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondactivity);
}
}
日志猫
FATAL EXCEPTION: main >android.content.ActivityNotFoundException:
No Activity found to handle Intent
{ act=com.example.simpleapp.SecondActivity.java }
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
android.app.Activity.startActivityForResult(Activity.java:3370)
com.example.simpleapp.MainActivity.onClick(MainActivity.java:22)
android.view.View.performClick(View.java:4204)
android.view.View$PerformClick.run(View.java:17355)
我想我可能会遗漏一些声明.....请告知