简体   繁体   English

当我尝试创建ListActivity进行其他活动时,它只是说“不幸的是,ReptileKeeper已停止”

[英]When i try to create a ListActivity to get to other activities it just says “Unfortunately, ReptileKeeper has stopped”

This is my code and i want to be able to click on one of the buttons of the suborder and then get to the new activity that matches the suborder. 这是我的代码,我希望能够单击子订单的按钮之一,然后转到与子订单匹配的新活动。 Can anyone tell me why it doesn't work? 谁能告诉我为什么它不起作用?

My menu class to access the suborder activities: 我的菜单类访问子订单活动:

  package com.xeecros.reptilekeeper;

    import android.os.Bundle;
    import android.app.Activity;
    import android.app.ListActivity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;

public class MainMenu extends ListActivity {

    String suborder[] = {"Serpentes",
        "Lacertilia", "Chelonia"};



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(MainMenu.this,
                android.R.layout.simple_list_item_1, suborder));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        super.onListItemClick(l, v, position, id);
        String localposm = suborder[position];
        try{
        Class ourclass = Class.forName("com.xeecros.reptilekeeper." + localposm);
        Intent mintent = new Intent(MainMenu.this, ourclass);
        startActivity(mintent);
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }

        }

My Serpentes suborder activity i want it to be able to get to: 我希望我的Serpentes子订单活动能够达到:

 package com.xeecros.reptilekeeper;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Serpentes extends ListActivity {

    String snakefam[] = {"Boidae", "Colubridae",
            "Elapidae", "Pythonidae", "Viperidae"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(Serpentes.this,
                android.R.layout.simple_list_item_1, snakefam));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        super.onListItemClick(l, v, position, id);
        try{
        Class ourclass = Class.forName("com.xeecros.reptilekeeper.MainMenu");
        Intent sintent = new Intent(Serpentes.this, ourclass);
        startActivity(sintent);
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
    }

}

I appreciate any help thank you very much. 非常感谢您的帮助。

my log cat: 我的原木猫:

 04-19 19:52:35.731: I/Process(1316): Sending signal. PID: 1316 SIG: 9
04-19 19:59:41.911: D/dalvikvm(1397): GC_FOR_ALLOC freed 44K, 6% free 2655K/2820K, paused 38ms, total 40ms
04-19 19:59:41.921: I/dalvikvm-heap(1397): Grow heap (frag case) to 3.780MB for 1127536-byte allocation
04-19 19:59:41.971: D/dalvikvm(1397): GC_FOR_ALLOC freed 2K, 5% free 3754K/3924K, paused 42ms, total 42ms
04-19 19:59:42.021: D/dalvikvm(1397): GC_CONCURRENT freed <1K, 5% free 3757K/3924K, paused 4ms+12ms, total 52ms
04-19 19:59:42.251: D/gralloc_goldfish(1397): Emulator without GPU emulation detected.
04-19 19:59:58.691: D/AndroidRuntime(1397): Shutting down VM
04-19 19:59:58.691: W/dalvikvm(1397): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-19 19:59:58.721: E/AndroidRuntime(1397): FATAL EXCEPTION: main
04-19 19:59:58.721: E/AndroidRuntime(1397): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xeecros.reptilekeeper/com.xeecros.reptilekeeper.Serpentes}; have you declared this activity in your AndroidManifest.xml?
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Activity.startActivityForResult(Activity.java:3370)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Activity.startActivityForResult(Activity.java:3331)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Activity.startActivity(Activity.java:3566)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.Activity.startActivity(Activity.java:3534)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at com.xeecros.reptilekeeper.MainMenu.onListItemClick(MainMenu.java:35)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.widget.AbsListView$1.run(AbsListView.java:3423)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.os.Handler.handleCallback(Handler.java:725)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.os.Looper.loop(Looper.java:137)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at java.lang.reflect.Method.invokeNative(Native Method)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at java.lang.reflect.Method.invoke(Method.java:511)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-19 19:59:58.721: E/AndroidRuntime(1397):     at dalvik.system.NativeStart.main(Native Method)
04-19 20:00:02.481: I/Process(1397): Sending signal. PID: 1397 SIG: 9

Each Activity have to be registered in the manifest file. 每个活动都必须在清单文件中注册。 It seems that you haven't done this. 看来您还没有这样做。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ... >

    <application
        ... >
        <activity
            android:name=".YourActivity"
            ... />
    </application>
</manifest>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM