简体   繁体   English

错误,即使活动存在于AndroidManifest.xml中

[英]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. 您可以按照以下步骤进行操作。

  1. Put breakpoint on line 312 将断点放在第312行
  2. Debug your application and let breakpoint to fire 调试您的应用程序并让断点触发
  3. Just get mouse pointer on variable and you will get the value of variable 只需将鼠标指针放在变量上,您将获得变量的值
    OR 要么
  4. Right click on variable name and select Inspect 右键单击变量名称,然后选择检查

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.

相关问题 Activity 未在 AndroidManifest.xml 中声明,即使它是 - Activity not declared in AndroidManifest.xml even if it is Android:无法找到显式活动 class,即使我在 AndroidManifest.xml 中定义了它? - Android: Unable to find explicit activity class even though I defined it in AndroidManifest.xml? 即使Appnext SDK不在AndroidManifest.xml中,也如何开始其广告活动? - How could Appnext SDK start its own activity for its ads even if it's not in AndroidManifest.xml? 以编程方式检查是否在AndroidManifest.xml中声明了Activity - Programmatically check if an Activity is declared in the AndroidManifest.xml 在 AndroidManifest.xml 中声明活动以使用 Intent - Declare activity in AndroidManifest.xml to use an Intent Eclipse删除AndroidManifest.xml中的活动? - Eclipse removing activity in AndroidManifest.xml? 活动“MainActivity”未在 AndroidManifest.xml 中声明,尽管它在那里 - The activity 'MainActivity' is not declared in AndroidManifest.xml although it is there 无法找到明确的活动类。 在 AndroidManifest.xml 中 - Unable to find explicit activity class. in AndroidManifest.xml 错误您是否在 AndroidManifest.xml 中声明了此活动? - Error have you declared this activity in your AndroidManifest.xml? 您是否在AndroidManifest.xml中声明了此活动? 登录活动 - Have you declared this activity in your AndroidManifest.xml ? LoginActivity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM