need help in loading activity
I have created following activity
package com.ali.test;
import android.app.Activity;
import android.content.Intent;
import 开发者_开发技巧android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Test extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*
OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(this, Second.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
};
*/
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(this, Second.class));
}
}
and want to load
package com.ali.test;
import android.app.Activity;
import android.os.Bundle;
public class Second extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
but when i press the buttons app closes unexeptionaly
you should Add secondActivity class in manifest file.
<activity android:name=".Second "></activity>
Have you registered the Second Activity in your AndroidManifest.xml? here: AndroidManifest.xml activity
It must be due to following:
1.check the button1 id in XML also..Both should match
2.Test Class and Second class must be defined in manifest..
Also do not forgot to Replace onClick with...
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(Test.this, Second.class));
}
For more detail please specify the error
精彩评论