user1130126
user1130126

Reputation: 1

List Activity not working

Hey guys I'm a new programmer, I'm trying to make a list menu in Android 2.2 I've tried every tutorial I can find and I keep getting an Instrumental class error When I use debug to try the app on my phone

Heres my Code

package com.IrishSign.app;

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 Menu extends ListActivity {

String alphabet[] = { "Aa", "Bb", "Cc", "Dd", "Ee", "Ff",};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this, 

android.R.layout.simple_list_item_1, alphabet));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String selectedClass = alphabet[position];
    try{
    Class OurClass = Class.forName("com.IrishSign.app." + selectedClass);
    Intent OurIntent = new Intent(Menu.this, OurClass);
    startActivity(OurIntent);
    }catch (ClassNotFoundException e){
        e.printStackTrace();
    }
}

}

The List works but when I click on an item it force closes and I get the error on my computer,

P.S: I've always wanted to start coding since I was ten and I'm heading off to college next year and would like to have bit of expierience with Java and android so it would really help me out if you guys could help me out.

Edit Log cat

 01-04 19:10:14.608: W/System.err(3931): java.lang.ClassNotFoundException:         com.IrishSign.app.Aa
01-04 19:10:14.608: W/System.err(3931):     at java.lang.Class.classForName(Native Method)
01-04 19:10:14.618: W/System.err(3931):     at java.lang.Class.forName(Class.java:234)
01-04 19:10:14.618: W/System.err(3931):     at java.lang.Class.forName(Class.java:181)
01-04 19:10:14.618: W/System.err(3931):     at com.IrishSign.app.Menu.onListItemClick(Menu.java:29)
01-04 19:10:14.618: W/System.err(3931):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
01-04 19:10:14.628: W/System.err(3931):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-04 19:10:14.628: W/System.err(3931):     at android.widget.ListView.performItemClick(ListView.java:3513)
01-04 19:10:14.628: W/System.err(3931):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
01-04 19:10:14.628: W/System.err(3931):     at android.os.Handler.handleCallback(Handler.java:587)
01-04 19:10:14.628: W/System.err(3931):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-04 19:10:14.638: W/System.err(3931):     at android.os.Looper.loop(Looper.java:130)
01-04 19:10:14.638: W/System.err(3931):     at android.app.ActivityThread.main(ActivityThread.java:3835)
01-04 19:10:14.638: W/System.err(3931):     at java.lang.reflect.Method.invokeNative(Native Method)
01-04 19:10:14.638: W/System.err(3931):     at java.lang.reflect.Method.invoke(Method.java:507)
01-04 19:10:14.638: W/System.err(3931):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-04 19:10:14.638: W/System.err(3931):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-04 19:10:14.648: W/System.err(3931):     at dalvik.system.NativeStart.main(Native Method)
01-04 19:10:14.648: W/System.err(3931): Caused by: java.lang.NoClassDefFoundError: com.IrishSign.app.Aa
01-04 19:10:14.648: W/System.err(3931):     ... 17 more
01-04 19:10:14.658: W/System.err(3931): Caused by: java.lang.ClassNotFoundException: com.IrishSign.app.Aa in loader dalvik.system.PathClassLoader[/data/app/com.IrishSign.app-1.apk]
01-04 19:10:14.658: W/System.err(3931):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
01-04 19:10:14.668: W/System.err(3931):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
01-04 19:10:14.668: W/System.err(3931):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-04 19:10:14.668: W/System.err(3931):     ... 17 more

Upvotes: 0

Views: 274

Answers (1)

Jap Mul
Jap Mul

Reputation: 18789

Define all the activities in you Manifest file like this:

<activity android:name=".ActivityName"></activity>

Include the . in front of the name. Place this within the Application tags.

Upvotes: 1

Related Questions