Search code examples
androidlistactivity

The newBoston vid 21 list load but when click on list nothing happens


I am new in android application development and using The New Boston tutorial. at lesson 21,when i run my code,everything is ok but when i click on lists activities not running! . Please help. I checked everything but i cant understand :(.

Manifest

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test1.zip.com"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Splash"
            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=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.zip.test1.MENU" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Action"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.zip.test1.ACTION" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Test1Activity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.zip.test1.TEST1ACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>

Menu.java

package test1.zip.com;

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 classes[] = { "Test1Activity", "Action", "Test1", "Test2" };


    @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, classes));

    }


    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        String cheese = classes[position];
        try {

            Class ourclass = Class.forName("com.zip.test1." + cheese);
            Intent ourIntent = new Intent(Menu.this, ourclass);
            startActivity(ourIntent);
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

}

logcat

11-03 05:52:24.744: D/AndroidRuntime(7191): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-03 05:52:24.744: D/AndroidRuntime(7191): CheckJNI is OFF
11-03 05:52:24.920: D/AndroidRuntime(7191): Calling main entry com.android.commands.pm.Pm
11-03 05:52:24.924: D/AndroidRuntime(7191): Shutting down VM
11-03 05:52:24.936: D/dalvikvm(7191): GC_CONCURRENT freed 99K, 72% free 294K/1024K, external 0K/0K, paused 0ms+2ms
11-03 05:52:24.936: D/dalvikvm(7191): Debugger has detached; object registry had 1 entries
11-03 05:52:24.948: I/AndroidRuntime(7191): NOTE: attach of thread 'Binder Thread #1' failed
11-03 05:52:25.148: D/AndroidRuntime(7198): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-03 05:52:25.148: D/AndroidRuntime(7198): CheckJNI is OFF
11-03 05:52:25.349: D/AndroidRuntime(7198): Calling main entry com.android.commands.am.Am
11-03 05:52:25.356: I/ActivityManager(157): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=test1.zip.com/.Splash } from pid 7198
11-03 05:52:25.361: D/AndroidRuntime(7198): Shutting down VM
11-03 05:52:25.368: D/dalvikvm(7198): GC_CONCURRENT freed 100K, 70% free 316K/1024K, external 0K/0K, paused 0ms+3ms
11-03 05:52:25.372: D/dalvikvm(7198): Debugger has detached; object registry had 1 entries
11-03 05:52:25.380: I/AndroidRuntime(7198): NOTE: attach of thread 'Binder Thread #2' failed
11-03 05:52:33.905: W/System.err(7002): java.lang.ClassNotFoundException: com.zip.test1.Test1Activity
11-03 05:52:33.908: W/System.err(7002):     at java.lang.Class.classForName(Native Method)
11-03 05:52:33.908: W/System.err(7002):     at java.lang.Class.forName(Class.java:234)
11-03 05:52:33.908: W/System.err(7002):     at java.lang.Class.forName(Class.java:181)
11-03 05:52:33.908: W/System.err(7002):     at test1.zip.com.Menu.onListItemClick(Menu.java:33)
11-03 05:52:33.908: W/System.err(7002):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
11-03 05:52:33.908: W/System.err(7002):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
11-03 05:52:33.908: W/System.err(7002):     at android.widget.ListView.performItemClick(ListView.java:3513)
11-03 05:52:33.908: W/System.err(7002):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
11-03 05:52:33.908: W/System.err(7002):     at android.os.Handler.handleCallback(Handler.java:587)
11-03 05:52:33.908: W/System.err(7002):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 05:52:33.908: W/System.err(7002):     at android.os.Looper.loop(Looper.java:130)
11-03 05:52:33.908: W/System.err(7002):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-03 05:52:33.912: W/System.err(7002):     at java.lang.reflect.Method.invokeNative(Native Method)
11-03 05:52:33.912: W/System.err(7002):     at java.lang.reflect.Method.invoke(Method.java:507)
11-03 05:52:33.912: W/System.err(7002):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-03 05:52:33.912: W/System.err(7002):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-03 05:52:33.912: W/System.err(7002):     at dalvik.system.NativeStart.main(Native Method)
11-03 05:52:33.912: W/System.err(7002): Caused by: java.lang.NoClassDefFoundError: com.zip.test1.Test1Activity
11-03 05:52:33.912: W/System.err(7002):     ... 17 more
11-03 05:52:33.912: W/System.err(7002): Caused by: java.lang.ClassNotFoundException: com.zip.test1.Test1Activity in loader dalvik.system.PathClassLoader[/data/app/test1.zip.com-2.apk]
11-03 05:52:33.916: W/System.err(7002):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-03 05:52:33.916: W/System.err(7002):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-03 05:52:33.916: W/System.err(7002):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-03 05:52:33.916: W/System.err(7002):     ... 17 more

Test1Activity.java package test1.zip.com;

import android.app.Activity;
import android.os.Bundle;


public class Test1Activity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

i think the problem is in this part

try {
              Class ourclass = Class.forName("com.zip.test1." + cheese);
              Intent ourIntent = new Intent(Menu.this, ourclass);
              startActivity(ourIntent);
          }
          catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }

i change to this and click on list works ! but ofcourse just go to action class.

Intent ourIntent = new Intent("com.zip.test1.ACTION");
        startActivity(ourIntent);

Solution

  • Okay i got this.The thing is in your manifest files you call the package.

     package="test1.zip.com"
    

    But, in your activity part of the manifest you are trying to call

                 <intent-filter>
                    <action android:name="com.zip.test1.MENU" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
    

    so if you change all intent filters to start with

     "test1.zip.com"
    

    instead of

    "com.zip.test1"
    

    it will be fixed.