私はプログラミングを始めたばかりで、スウェーデンの法律書の Android バージョンを作成しています。コードにエラーはありませんが、エミュレーターで実行しようとすると起動しますが、ボタンを押すとすぐに「残念ながら、アプリの名前が停止しました」と表示されます。
私はこのような他の多くのスレッドを調べましたが、それらはすべてコード固有のものであり、したがって私には役に立ちません.
私はエクリプスを使用しています。
それで、親切な魂が私がしたことを見て間違いを見つけるのを助けることができるかどうか疑問に思っていましたか?
これは「Activity_Main_activity.xml」のコーディングです。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HuvudMeny" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Kapitel 1, Om Brott och Brottspåföljder"
android:onClick = "kapett" />
ご覧のとおり、非常にシンプルです。
MainActivity.java コーディングは次のとおりです。
import com.example.brottsbalken.Kap1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
public class HuvudMeny extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_huvud_meny);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_huvud_meny, menu);
return true;
}
public void kapett(View view) {
Intent intent1 = new Intent(this, Kap1.class);
startActivity(intent1);
編集: LogCat を追加しました。これが必要だとは知りませんでした、ごめんなさい!
LogCat:
03-27 16:33:46.371: E/Trace(795): error opening trace file: No such file or directory (2)
03-27 16:33:46.371: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:46.371: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:46.371: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:46.491: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:46.491: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.311: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.311: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.341: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.411: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.541: D/libEGL(795): loaded /system/lib/egl/libEGL_emulation.so
03-27 16:33:47.611: D/(795): HostConnection::get() New Host Connection established 0x2a14b468, tid 795
03-27 16:33:47.623: D/libEGL(795): loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-27 16:33:47.680: D/libEGL(795): loaded /system/lib/egl/libGLESv2_emulation.so
03-27 16:33:47.861: W/EGL_emulation(795): eglSurfaceAttrib not implemented
03-27 16:33:47.901: D/OpenGLRenderer(795): Enabling debug mode 0
03-27 16:33:47.901: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.910: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:47.921: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.021: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.021: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.071: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.091: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.091: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.101: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.110: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.331: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.331: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.351: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.370: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.712: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:48.973: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:33:49.110: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.451: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.451: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.505: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.781: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.781: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.821: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.821: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:24.831: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:25.215: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:25.215: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.907: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.910: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.921: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.940: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.940: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.951: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.951: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.960: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.960: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:26.990: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:27.090: D/dalvikvm(795): GC_CONCURRENT freed 73K, 7% free 2718K/2908K, paused 5ms+4ms, total 164ms
03-27 16:36:27.191: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:27.191: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:27.201: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:27.221: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0
03-27 16:36:27.260: D/AndroidRuntime(795): Shutting down VM
03-27 16:36:27.260: W/dalvikvm(795): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
03-27 16:36:27.321: E/AndroidRuntime(795): FATAL EXCEPTION: main
03-27 16:36:27.321: E/AndroidRuntime(795): java.lang.IllegalStateException: Could not execute method of the activity
03-27 16:36:27.321: E/AndroidRuntime(795): at android.view.View$1.onClick(View.java:3597)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.view.View.performClick(View.java:4202)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.view.View$PerformClick.run(View.java:17340)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.os.Handler.handleCallback(Handler.java:725)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.os.Handler.dispatchMessage(Handler.java:92)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.os.Looper.loop(Looper.java:137)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-27 16:36:27.321: E/AndroidRuntime(795): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 16:36:27.321: E/AndroidRuntime(795): at java.lang.reflect.Method.invoke(Method.java:511)
03-27 16:36:27.321: E/AndroidRuntime(795): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-27 16:36:27.321: E/AndroidRuntime(795): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-27 16:36:27.321: E/AndroidRuntime(795): at dalvik.system.NativeStart.main(Native Method)
03-27 16:36:27.321: E/AndroidRuntime(795): Caused by: java.lang.reflect.InvocationTargetException
03-27 16:36:27.321: E/AndroidRuntime(795): at java.lang.reflect.Method.invokeNative(Native Method)
<?xml version="1.0" encoding="utf-8"?>
03-27 16:36:27.321: E/AndroidRuntime(795): at java.lang.reflect.Method.invoke(Method.java:511)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.view.View$1.onClick(View.java:3592)
03-27 16:36:27.321: E/AndroidRuntime(795): ... 11 more
03-27 16:36:27.321: E/AndroidRuntime(795): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {nackagymnasium.brottsbalken2/com.example.brottsbalken.Kap1}; have you declared this activity in your AndroidManifest.xml?
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Activity.startActivityForResult(Activity.java:3370)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Activity.startActivityForResult(Activity.java:3331)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Activity.startActivity(Activity.java:3566)
03-27 16:36:27.321: E/AndroidRuntime(795): at android.app.Activity.startActivity(Activity.java:3534)
03-27 16:36:27.321: E/AndroidRuntime(795): at nackagymnasium.brottsbalken2.HuvudMeny.kapett(HuvudMeny.java:30)
03-27 16:36:27.321: E/AndroidRuntime(795): ... 14 more
03-27 16:41:28.431: I/Process(795): Sending signal. PID: 795 SIG: 9
これがマニフェストです。私にはかなり正しいように見えます...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nackagymnasium.brottsbalken2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="nackagymnasium.brottsbalken2.HuvudMeny"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="nackagymnasium.brottsbalken2.Kap1"
android:label="@string/title_activity_kap1" >
</activity>
「メイン アクティビティ」の名前を「Huvud Meny」に変更しました。
私はそれが意図(天才)に何か問題があるに違いないと考えましたが、それが何であるかはわかりません。
誰かが時間を割いて私を助けてくれたら、私はとても幸せです!