私はAndroid2.2とEclipseを使用してAndroidアプリを作成しています。アクティビティを「CoverPageApp.java」から「LoginActivity.java」に変更してから別のアクティビティに変更する必要があるシンプルなアプリです。しかし、CoverPageApp.javaの「スタートボタン」をクリックすると、アプリの強制が終了します。
LoginActivity.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);
}
});
}
}
LogCat
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)