0

我刚刚开始编程,正在制作瑞典法律书籍的安卓版本。我的代码没有错误,但是当我尝试在模拟器中运行它时,它会启动,但只要按下一个按钮,它就会显示“不幸的是,应用程序的名称已停止。”

我查看了许多其他类似的线程,但它们都是特定于代码的,因此对我没有用。

我正在使用 Eclipse。

所以,我想知道是否有任何善良的灵魂可以通过我所做的事情来帮助我找到错误?

这是“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。不知道你需要这个,对不起!

日志猫:

    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”。

我想这一定是意图(天才)有问题,但我不知道它是什么。

如果有人花时间帮助我,我会非常高兴!

4

1 回答 1

0

您是否在 AndroidManifest.xml 中声明了此活动?

嗯,是吗?

请参阅向 AndroidManifest 添加新活动?

于 2013-03-27T17:40:07.503 回答