Xtreme
Xtreme

Reputation: 1591

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. But it's there.

LogCat error

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. When you click on the button, it runs in the package com.kids.playground.math

enter image description here

My 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

 @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 ..."

Upvotes: 0

Views: 607

Answers (2)

CSharp
CSharp

Reputation: 1583

You need to debug and have to check value of all the variables, used in if condition. 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
  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...

Upvotes: 1

Jose L Ugia
Jose L Ugia

Reputation: 6250

Debug and tell us the value of all the vars in this line. One (or more) of them is going to be 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.

Upvotes: 0

Related Questions