收到无法启动活动 vTestSession 的错误,可能是因为不在 AndroidManifest.xml 中。但它就在那里。
LogCat 错误
08-12 18:39:14.871: E/AndroidRuntime(987): FATAL EXCEPTION: main
08-12 18:39:14.871: E/AndroidRuntime(987): java.lang.IllegalStateException: Could not execute method of the activity
08-12 18:39:14.871: E/AndroidRuntime(987): at android.view.View$1.onClick(View.java:3591)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.view.View.performClick(View.java:4084)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.view.View$PerformClick.run(View.java:16966)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.os.Handler.handleCallback(Handler.java:615)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.os.Handler.dispatchMessage(Handler.java:92)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.os.Looper.loop(Looper.java:137)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-12 18:39:14.871: E/AndroidRuntime(987): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 18:39:14.871: E/AndroidRuntime(987): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 18:39:14.871: E/AndroidRuntime(987): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-12 18:39:14.871: E/AndroidRuntime(987): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-12 18:39:14.871: E/AndroidRuntime(987): at dalvik.system.NativeStart.main(Native Method)
08-12 18:39:14.871: E/AndroidRuntime(987): Caused by: java.lang.reflect.InvocationTargetException
08-12 18:39:14.871: E/AndroidRuntime(987): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 18:39:14.871: E/AndroidRuntime(987): at java.lang.reflect.Method.invoke(Method.java:511)
08-12 18:39:14.871: E/AndroidRuntime(987): at android.view.View$1.onClick(View.java:3586)
08-12 18:39:14.871: E/AndroidRuntime(987): ... 11 more
08-12 18:39:14.871: E/AndroidRuntime(987): Caused by: java.lang.NullPointerException
08-12 18:39:14.871: E/AndroidRuntime(987): at com.kids.playground.math.vTestSession.getcurrentquestion(vTestSession.java:312)
08-12 18:39:14.871: E/AndroidRuntime(987): at com.kids.playground.math.vTestSession.setuparun(vTestSession.java:132)
08-12 18:39:14.871: E/AndroidRuntime(987): at com.kids.playground.math.vTestSession.ans1clicked(vTestSession.java:342)
08-12 18:39:14.871: E/AndroidRuntime(987): ... 14 more
我在 com.kids.playground 包中有一个带有按钮的类。当您单击该按钮时,它会在 com.kids.playground.math 包中运行
我的 AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kids.playground"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.kids.playground.math.DMG"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vSplash"
android:theme="@style/Theme.Transparent">
</activity>
<activity android:name="com.kids.playground.math.vTestSession"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vStats"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vHistoryStats"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vEasystats"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vNormalstats"
android:label="@string/app_name">
</activity>
<activity android:name="com.kids.playground.math.vHardstats"
android:label="@string/app_name">
</activity>
<receiver android:name="com.kids.playground.math.MyIntentReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.kids.playground.math.PrepareOperationSet" />
</intent-filter>
</receiver>
</application>
</manifest>
编辑 - 第 306-317 行
@SuppressWarnings("unchecked")
private ArrayList<String> getcurrentquestion() {
ArrayList<String> retval = new ArrayList<String>();
Random r = new Random();
//Check if the current index is not over size of question set and maximum number of questions then return null
if( vTestSession.currentindex > this.numquestions-1 || vTestSession.currentindex > this.questions.size()-1) { return null; }
int qindex = r.nextInt(this.questions.size());
retval = (ArrayList<String>) this.questions.get(qindex);
return retval;
}
第 312 行是注释“//Check if the current index ...”下的 if 语句