简体   繁体   中英

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:

 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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