获取活动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行是注释下的if语句&#34; //检查当前索引是否...&#34;
答案 0 :(得分:1)
您需要调试并且必须检查在if条件中使用的所有变量的值。在这里,您需要验证所有变量是否包含预期值而不是空值。你也可以按照以下方式进行操作。
我希望这会对你有帮助......
答案 1 :(得分:0)
调试并告诉我们此行中所有变量的值。 其中一个(或多个)将为空。 如果你发现原因,你的问题就解决了。
很可能你没有在之前的代码中初始化它们。