newBoston vid 21 列表加载但是当点击列表时没有任何反应

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

我是 android 应用程序开发和使用 The New Boston 教程的新手。在第 21 课,当我 运行 我的代码时,一切正常,但是当我单击列表活动时,我 运行ning! . 请帮忙。我检查了所有内容,但我无法理解:(.

清单

    <?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.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 包裹 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);
    }
}

我认为问题出在这部分

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

我改成这个然后点击列表作品!但当然只是去行动 class.

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

尝试将 类 数组中的所有字符串更改为大写。 Aslo 在 Manifest 文件中声明您的所有活动,缺少 Test1 和 Test2。

这样投class

Class<?> c = null;  //<= this is what i say
if(StringClassname != null) {
try {
    c = Class.forName(StringClassname );
} catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
}
Intent intent = new Intent(mail.this, c);
startActivity(intent);

好的,我得到 this.The 东西在你称为包的清单文件中。

 package="test1.zip.com"

但是,在您试图调用的清单的 activity 部分中

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

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

因此,如果您将所有意图过滤器更改为以

开头
 "test1.zip.com"

而不是

"com.zip.test1"

会修复的。