android虚拟机中点击写好的button按钮显示unfortunately,项目has stopped。为什么不向下执行
packageandroid.activity_intent;importandroid.app.Activity;importandroid.os.Bundle;imp...
package android.activity_intent;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;
public class Activity_Intent extends Activity {
/** Called when the activity is first created. */
private Button myButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton=(Button)findViewById(R.id.myButtonId);
myButton.setOnClickListener(new MyButtonListener());
}
//监听器
class MyButtonListener implements android.view.View.OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
//生产一个Intent对象
Intent intent=new Intent();
intent.setClass(Activity_Intent.this, Intent.class);
Activity_Intent.this.startActivity(intent);
}
}
} 展开
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;
public class Activity_Intent extends Activity {
/** Called when the activity is first created. */
private Button myButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton=(Button)findViewById(R.id.myButtonId);
myButton.setOnClickListener(new MyButtonListener());
}
//监听器
class MyButtonListener implements android.view.View.OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
//生产一个Intent对象
Intent intent=new Intent();
intent.setClass(Activity_Intent.this, Intent.class);
Activity_Intent.this.startActivity(intent);
}
}
} 展开
1个回答
展开全部
你这个肯定有问题呗,Intent intent = new Intent(Activity_Intent.this,OtherActivity.class);
Activity_Intent.this.startActivity(intent);
不能用Intent.class
Activity_Intent.this.startActivity(intent);
不能用Intent.class
追问
谢谢啦,我解决了,我把那个类名改了,但是我还是想知道,为什么不能用Intent.class。是不是应为intent是关键字啊。我不是很懂android,我也是刚刚才看视频在学习。不过真的很感谢啦,我整了一个下午,都没有弄出来。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询