Android:the application has stopped unexpectedlypackage com.misoo.ex02;import android.app.Activity;import android.view.View.OnClickListener;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Ex02Activity exten
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 21:32:44
Android:the application has stopped unexpectedlypackage com.misoo.ex02;import android.app.Activity;import android.view.View.OnClickListener;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Ex02Activity exten
Android:the application has stopped unexpectedly
package com.misoo.ex02;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Ex02Activity extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.button);
Button btn2 = (Button)findViewById(R.id.button2);
btn.setOnClickListener(this);
btn2.setOnClickListener(this);
}
public void onClick(View v)
{
\x05switch(v.getId())
\x05{
\x05case R.id.button:
\x05\x05setTitle("this is OK button..");
\x05\x05break;
\x05case R.id.button2:
\x05\x05this.finish();
\x05\x05break;
\x05}
}
}
-----------------------------------------
main.xml
xml version="1.0" encoding="utf-8"?>
哪里出错了啊?
Android:the application has stopped unexpectedlypackage com.misoo.ex02;import android.app.Activity;import android.view.View.OnClickListener;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Ex02Activity exten
把logcat 里面的错误信息 贴出来 .
代码没错。我觉得应该是eclipse的老问题了,有时没有把最新的资源layout打包进apk。右击项目,build->clean一下就好。
注意大小写啊,xml里面的Button的B要大写,它是一个类的名字。其他地方貌似没有错吧