[英]Fault that the activity is not in AndroidManifest.xml even though it's there
Get an error that the activity vTestSession can not be started and may be because the is not in AndroidManifest.xml. 错误提示活动vTestSession无法启动,可能是因为AndroidManifest.xml中没有该活动。 But it's there.
但它在那里。
LogCat error 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
I have a class with a button in the package com.kids.playground. 我在com.kids.playground包中有一个带有按钮的类。 When you click on the button, it runs in the package com.kids.playground.math
当您单击该按钮时,它将在com.kids.playground.math包中运行
My AndroidManifest.xml 我的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>
Edit - Line 306-317 编辑-线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;
}
Line 312 is the if-statement under the comment "//Check if the current index ..." 第312行是注释“ //检查当前索引是否...”下的if语句。
You need to debug and have to check value of all the variables, used in if condition. 您需要调试,并且必须检查if条件中使用的所有变量的值。 Here you need to verify that all the variables contain expected values and not null values.
在这里,您需要验证所有变量都包含期望值而不是空值。 You can follow following for the same.
您可以按照以下步骤进行操作。
I hope this will help you... 我希望这能帮到您...
Debug and tell us the value of all the vars in this line. 调试并告诉我们此行中所有var的值。 One (or more) of them is going to be null.
其中一个(或多个)将为null。 If you find out why, your problem is solved.
如果找出原因,您的问题就解决了。
It is very likely that you didn't initialized any of them in prior code. 您很可能没有在先前的代码中初始化任何一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.