写了一个简单的例子,就是从一个activity跳转到另一个activity,一个叫LoginDemoActivity,加一个叫NoteActiviy。跳转的代码段如下:
btnLogin=(Button)findViewById(R.id.btnLogin);
??????? btnLogin.setOnClickListener(new Button.OnClickListener(){
??? ??? ??? public void onClick(View v) {
??? ??? ??? ??? if("[email protected]".equals(account.getText().toString().trim())
??? ??? ??? ??? ??? ??? && "xxxxxxxxxxx".equals(password.getText().toString().trim())){
??? ??? ??? ??? ??? Intent intent=new Intent();
??? ??? ??? ??? ??? intent.setClass(LoginDemoActivity.this, NoteActivity.class);
??? ??? ??? ??? ??? startActivity(intent);
??? ??? ??? ??? ??? LoginDemoActivity.this.finish();
??? ??? ??? ??? }else{
??? ??? ??? ??? ??? Toast.makeText(LoginDemoActivity.this, "输入的帐号或密码有误!", Toast.LENGTH_LONG).show();
??? ??? ??? ??? }
??? ??? ??? }
??????? ???
??????? });
?
在NoteActivity的代码如下:
protected void onCreate(Bundle savedInstanceState) {
??? ???
??? ??? setContentView(R.layout.note);
??? ??? btnClose=(Button)findViewById(R.id.btnClose);
??? ??? btnClose.setOnClickListener(new Button.OnClickListener(){
??? ??? ??? public void onClick(View v) {
??? ??? ??? ??? NoteActivity.this.finish();
??? ??? ??? }
??? ??? ???
??? ??? });
??? }
在AndroidMainfest.xml中已经注册了这两个activity。
?
但当程序运行起来时,抛出如下异常:
android.app.SuperNotCalledException did not call through to supper onCreate();
?
Google了一把,原来是在NoteActivity的onCreate()函数中没有加super.onCreate(savedInstanceState);
修改代码后,运行正常,修改后的代码为:
protected void onCreate(Bundle savedInstanceState) {
??? ??? super.onCreate(savedInstanceState);
??? ??? setContentView(R.layout.note);
??? ??? btnClose=(Button)findViewById(R.id.btnClose);
??? ??? btnClose.setOnClickListener(new Button.OnClickListener(){
??? ??? ??? public void onClick(View v) {
??? ??? ??? ??? NoteActivity.this.finish();
??? ??? ??? }
??? ??? ???
??? ??? });
??? }
注意红色高亮处!