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

时间:2013-04-19 19:54:59

标签: java android eclipse

这是我的代码,我希望能够点击子订单的其中一个按钮,然后转到与子订单匹配的新活动。谁能告诉我为什么它不起作用?

我的菜单类访问子订单活动:

  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();
        }

        }

我的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();
        }
    }

}

非常感谢你的帮助。

我的日志猫:

 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

1 个答案:

答案 0 :(得分:0)

每个活动都必须在清单文件中注册。看来你还没有这样做。

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

    <application
        ... >
        <activity
            android:name=".YourActivity"
            ... />
    </application>
</manifest>
相关问题