-1

我查找了有关如何从列表视图而不是常规按钮启动活动的教程,我认为我是对的,但由于某种原因,我的模拟器没有启动第二个活动,它只是显示我按下了按钮但什么也没有发生。

这是我的 MainActivityThree.java 的副本...

package testing.android.application.three;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivityThree extends ListActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   //setContentView(R.layout.activity_main_activity_three);
    String[] names = new String[]{"Test 5","Test 10","Test 15","Test 20","Test 25","Test 30"};
    setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,names));

}

private static final int Test 5 = 0;
private static final int Test 10 = 1;

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    Class <?> MainActivityNext = null;
    switch(position) {
        case Test 5 :
            MainActivityNext = MainActivityNext.class;
            break;
       //keep the same logic for other cases
    }
    Intent Test 5Intent = new Intent(MainActivityThree.this, MainActivityNext);
    startActivity(Test 5Intent);

}

}

这是我的 MainActivityNext.java 的副本...

package testing.android.application.three;

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

public class MainActivityNext extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_activity_next);

}

}

这是我的 AndroidManifest.xml 的副本...

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

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/AppName"
    android:theme="@style/ThreeTheme" >
    <activity
        android:name="testing.android.application.three.MainActivityThree"
        android:label="@string/AppName" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="testing.android.application.three.MainActivityNext"
        android:label="@string/title_activity_main_activity_next" >
    </activity>
    <activity
        android:name="testing.android.application.three.MainActivityTGS"
        android:label="@string/title_activity_main_activity_tgs" >
    </activity>
</application>

这是我的 activity_main_activity_next.xml 的副本...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivityNext" >

</RelativeLayout>

这是我的 actiity_main_activity_Three.xml 的副本...

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingLeft="8dp"
 android:paddingRight="8dp"
 tools:context=".MainActivityThree" >

</LinearLayout>

还有我的 LogCat 的副本...

06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3435)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.View.dispatchTouchEvent(View.java:7246)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.View.dispatchPointerEvent(View.java:7426)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.os.MessageQueue.nativePollOnce(Native Method)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.os.MessageQueue.next(MessageQueue.java:125)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.os.Looper.loop(Looper.java:124)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:10:39.389: E/AndroidRuntime(2686):     at dalvik.system.NativeStart.main(Native Method)
06-01 04:13:31.379: D/dalvikvm(2794): GC_FOR_ALLOC freed 50K, 7% free 2538K/2708K, paused 42ms, total 87ms
06-01 04:13:31.389: I/dalvikvm-heap(2794): Grow heap (frag case) to 3.666MB for 1127536-byte allocation
06-01 04:13:31.479: D/dalvikvm(2794): GC_FOR_ALLOC freed 1K, 5% free 3639K/3812K, paused 81ms, total 81ms
06-01 04:13:31.549: D/dalvikvm(2794): GC_CONCURRENT freed <1K, 5% free 3646K/3812K, paused 5ms+12ms, total 71ms
06-01 04:13:32.459: D/gralloc_goldfish(2794): Emulator without GPU emulation detected.
06-01 04:13:55.189: E/InputEventReceiver(2794): Exception dispatching input event.
06-01 04:13:55.189: E/MessageQueue-JNI(2794): Exception in MessageQueue callback: handleReceiveCallback
06-01 04:13:55.261: E/MessageQueue-JNI(2794): java.lang.NullPointerException
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.content.ComponentName.<init>(ComponentName.java:76)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.content.Intent.<init>(Intent.java:3491)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at testing.android.application.three.MainActivityThree.onListItemClick(MainActivityThree.java:34)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3435)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.View.dispatchTouchEvent(View.java:7246)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.View.dispatchPointerEvent(View.java:7426)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.os.MessageQueue.nativePollOnce(Native Method)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.os.MessageQueue.next(MessageQueue.java:125)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.os.Looper.loop(Looper.java:124)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:13:55.261: E/MessageQueue-JNI(2794):   at dalvik.system.NativeStart.main(Native Method)
06-01 04:13:55.261: D/AndroidRuntime(2794): Shutting down VM
06-01 04:13:55.261: W/dalvikvm(2794): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-01 04:13:55.309: E/AndroidRuntime(2794): FATAL EXCEPTION: main
06-01 04:13:55.309: E/AndroidRuntime(2794): java.lang.NullPointerException
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.content.ComponentName.<init>(ComponentName.java:76)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.content.Intent.<init>(Intent.java:3491)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at testing.android.application.three.MainActivityThree.onListItemClick(MainActivityThree.java:34)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3435)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.View.dispatchTouchEvent(View.java:7246)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2168)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1903)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.View.dispatchPointerEvent(View.java:7426)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.os.MessageQueue.nativePollOnce(Native Method)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.os.MessageQueue.next(MessageQueue.java:125)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.os.Looper.loop(Looper.java:124)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:13:55.309: E/AndroidRuntime(2794):     at dalvik.system.NativeStart.main(Native Method)
06-01 04:13:58.309: I/Process(2794): Sending signal. PID: 2794 SIG: 9
06-01 04:14:05.680: E/Trace(2835): error opening trace file: No such file or directory (2)
06-01 04:14:06.710: D/dalvikvm(2835): GC_FOR_ALLOC freed 54K, 7% free 2539K/2712K, paused 296ms, total 350ms
06-01 04:14:06.771: I/dalvikvm-heap(2835): Grow heap (frag case) to 3.666MB for 1127536-byte allocation
06-01 04:14:06.980: D/dalvikvm(2835): GC_FOR_ALLOC freed 1K, 5% free 3639K/3816K, paused 202ms, total 202ms
06-01 04:14:07.080: D/dalvikvm(2835): GC_CONCURRENT freed <1K, 4% free 3664K/3816K, paused 13ms+18ms, total 100ms
06-01 04:14:07.400: D/gralloc_goldfish(2835): Emulator without GPU emulation detected.
06-01 04:14:09.749: D/AndroidRuntime(2835): Shutting down VM
06-01 04:14:09.749: W/dalvikvm(2835): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-01 04:14:09.789: E/AndroidRuntime(2835): FATAL EXCEPTION: main
06-01 04:14:09.789: E/AndroidRuntime(2835): java.lang.NullPointerException
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.content.ComponentName.<init>(ComponentName.java:76)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.content.Intent.<init>(Intent.java:3491)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at testing.android.application.three.MainActivityThree.onListItemClick(MainActivityThree.java:34)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.os.Handler.handleCallback(Handler.java:725)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.os.Looper.loop(Looper.java:137)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:14:09.789: E/AndroidRuntime(2835):     at dalvik.system.NativeStart.main(Native Method)
06-01 04:14:12.179: I/Process(2835): Sending signal. PID: 2835 SIG: 9
06-01 04:15:20.289: D/dalvikvm(2901): GC_FOR_ALLOC freed 57K, 7% free 2538K/2716K, paused 315ms, total 352ms
06-01 04:15:20.339: I/dalvikvm-heap(2901): Grow heap (frag case) to 3.666MB for 1127536-byte allocation
06-01 04:15:20.549: D/dalvikvm(2901): GC_FOR_ALLOC freed 1K, 5% free 3639K/3820K, paused 203ms, total 203ms
06-01 04:15:20.659: D/dalvikvm(2901): GC_CONCURRENT freed <1K, 5% free 3645K/3820K, paused 5ms+6ms, total 116ms
06-01 04:15:21.019: D/gralloc_goldfish(2901): Emulator without GPU emulation detected.
06-01 04:15:24.180: D/AndroidRuntime(2901): Shutting down VM
06-01 04:15:24.180: W/dalvikvm(2901): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-01 04:15:24.210: E/AndroidRuntime(2901): FATAL EXCEPTION: main
06-01 04:15:24.210: E/AndroidRuntime(2901): java.lang.NullPointerException
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.content.ComponentName.<init>(ComponentName.java:76)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.content.Intent.<init>(Intent.java:3491)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at testing.android.application.three.MainActivityThree.onListItemClick(MainActivityThree.java:34)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.os.Handler.handleCallback(Handler.java:725)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.os.Looper.loop(Looper.java:137)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:15:24.210: E/AndroidRuntime(2901):     at dalvik.system.NativeStart.main(Native Method)
06-01 04:15:27.310: I/Process(2901): Sending signal. PID: 2901 SIG: 9
06-01 04:17:10.740: D/dalvikvm(2981): GC_FOR_ALLOC freed 61K, 7% free 2538K/2720K, paused 320ms, total 340ms
06-01 04:17:10.810: I/dalvikvm-heap(2981): Grow heap (frag case) to 3.666MB for 1127536-byte allocation
06-01 04:17:11.030: D/dalvikvm(2981): GC_FOR_ALLOC freed 1K, 5% free 3639K/3824K, paused 220ms, total 220ms
06-01 04:17:11.150: D/dalvikvm(2981): GC_CONCURRENT freed <1K, 5% free 3639K/3824K, paused 12ms+34ms, total 129ms
06-01 04:17:11.500: D/gralloc_goldfish(2981): Emulator without GPU emulation detected.
06-01 04:17:22.369: D/AndroidRuntime(2981): Shutting down VM
06-01 04:17:22.402: W/dalvikvm(2981): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-01 04:17:22.429: E/AndroidRuntime(2981): FATAL EXCEPTION: main
06-01 04:17:22.429: E/AndroidRuntime(2981): java.lang.NullPointerException
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.content.ComponentName.<init>(ComponentName.java:76)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.content.Intent.<init>(Intent.java:3491)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at testing.android.application.three.MainActivityThree.onListItemClick(MainActivityThree.java:34)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.os.Handler.handleCallback(Handler.java:725)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.os.Looper.loop(Looper.java:137)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at java.lang.reflect.Method.invoke(Method.java:511)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-01 04:17:22.429: E/AndroidRuntime(2981):     at dalvik.system.NativeStart.main(Native Method)
06-01 04:17:24.779: I/Process(2981): Sending signal. PID: 2981 SIG: 9
4

3 回答 3

1

这是类未找到异常。您在类名字符串中错误地给出了“+”。尝试使用这个

    Class MainActivityNext = Class.forName("testing.android.application.three." + 
    "MainActivityNext.java");

而不是这个

Class MainActivityNext = Class.forName("testing.android.application.three. + MainActivityNext.java");
于 2013-05-31T03:54:49.310 回答
1

实际上,

你可能想考虑一些更简单的东西

Class<?> clasz =  MainActivityNext.class;
Intent MainActivityNextIntent = new Intent(this, clasz);
startActivity(MainActivityNextIntent);

但我的意思是,如果你总是知道你正在开始什么课程,为什么不是好的 ol':

Intent MainActivityNextIntent = new Intent(this, MainActivity.class);
startActivity(MainActivityNextIntent);

此外,如果将要启动的活动取决于被单击的项目,请通过定义它们final int,然后通过开关访问它们。例如,在课程开始时,定义一些可以开始的活动:

//Notice how I use All capitals and underscores? 
//It's a common convention for constants.
private static final int TEST_5 = 0;  //Starts MainActivityThree.class
private static final int TEST_10 = 1;  //Starts MainActivityTGS.class
private static final int TEST_15 = 2; //What do these other ones start? your call
private static final int TEST_20 = 3;
private static final int TEST_25 = 4;
private static final int TEST_30 = 5;

然后,根据选择的项目,运行 switch 语句:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Class <?> nextClass;
    switch(position) {
        case TEST_5 :
            nextClass = MainActivityThree.class;
            break;
        case TEST_10: 
            nextClass = MainActivityTGS.class;
            break;
        default:
           //because I don't know what other classes you plan on starting
           //I call return to avoid a null pointer exception
           //You have to make sure you set a class for the other list items
           //I just don't know which oens are they. 
           return;
       //keep the same logic for other cases
    }
    //This will only be called if the list item clicked was either TEST_5, Or TEST_10
    Intent nextClassIntent = new Intent(CurrentClass.this, nextClass);
    startActivity(nextClassIntent);
    }
于 2013-05-31T04:21:57.837 回答
0

在你try-catch简单地写

Intent MainActivityNextIntent = new Intent(this,MainActivityNext.class);
        startActivity(MainActivityNextIntent);

代替

Class MainActivityNext = Class.forName("testing.android.application.three. + MainActivityNext.java");
        Intent MainActivityNextIntent = new Intent(this,MainActivityNext);
        startActivity(MainActivityNextIntent);

如果你想这样做,就这样做

Class MainActivityNext = Class.forName("testing.android.application.three." + "MainActivityNext.java");
        Intent MainActivityNextIntent = new Intent(this,MainActivityNext);
        startActivity(MainActivityNextIntent);
于 2013-05-31T04:22:40.413 回答