我正在使用 android 2.2 和 eclipse 制作一个 android 应用程序。它是一个简单的应用程序,应该将活动从“CoverPageApp.java”更改为“LoginActivity.java”,然后再更改为另一个活动。但是当我单击 CoverPageApp.java 中的“开始按钮”时,应用程序强制关闭。
登录活动.java
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class LoginActivity extends Activity {
Button btnLinkToRegistrScrn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
addListenerOnButton();
btnLinkToRegistrScrn = (Button) findViewById(R.id.LinkToRegisterScreen);
}
public void addListenerOnButton() {
final Context context2 = this;
Button loginbtn1 = (Button) findViewById(R.id.btnLogin);
loginbtn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context2, DashboardActivity.class);
context2.startActivity(intent);
}
});
}
{
// Link to Register Screen
btnLinkToRegistrScrn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), CAActivity.class);
startActivity(i);
}
});
}
}
日志猫
05-31 12:37:08.620: D/AndroidRuntime(629): Shutting down VM
05-31 12:37:08.620: W/dalvikvm(629): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-31 12:37:08.630: E/AndroidRuntime(629): FATAL EXCEPTION: main
05-31 12:37:08.630: E/AndroidRuntime(629): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.app.Activity.startActivityForResult(Activity.java:2817)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.app.Activity.startActivity(Activity.java:2923)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.view.View.performClick(View.java:2408)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.view.View$PerformClick.run(View.java:8816)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.os.Handler.handleCallback(Handler.java:587)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.os.Handler.dispatchMessage(Handler.java:92)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.os.Looper.loop(Looper.java:123)
05-31 12:37:08.630: E/AndroidRuntime(629): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-31 12:37:08.630: E/AndroidRuntime(629): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 12:37:08.630: E/AndroidRuntime(629): at java.lang.reflect.Method.invoke(Method.java:521)
05-31 12:37:08.630: E/AndroidRuntime(629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-31 12:37:08.630: E/AndroidRuntime(629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-31 12:37:08.630: E/AndroidRuntime(629): at dalvik.system.NativeStart.main(Native Method)