Need Help With CallVoidMethod

I'm having trouble getting a call to a java method to work after invoking a jvm successfully. Find class and getmethodid work correctly, but the call to the method using CallVoidMethod returns an error (listed below).

Anyone know what I might be doing wrong?

The native code snippet:

jclass manager = env->FindClass("com/jnitester/MainClass");

if (manager == NULL) {

writetolog("** ERROR");

}

else

{

writetolog("successfully loaded com/jnitester/MainClass");

}

jmethodID loadcl_mid = env->GetMethodID(manager, "DoSomething", "()V");

if (loadcl_mid == NULL) {

writetolog("** ERROR: cannot find method ");

}

else

{

writetolog("java method loaded");

}

env->CallVoidMethod(manager, loadcl_mid);

The output I get is:

successfully loaded com/jnitester/MainClass

java method loaded

Invalid memory access of location 00000000 eip=9ec6d0cd

The java "MainClass" code is as follows:

package com.jnitester;

public class MainClass

{

public MainClass()

{

System.out.println("Here in MainClass");

}

public void DoSomething()

{

System.out.println("Here in Do Something");

}

}

[1305 byte] By [powerdroida] at [2007-11-27 1:51:55]
# 1

Many JNI calls must not only check for success (or instead of) they must also check for java exceptions after the call.

I suspect if you had done that then it would have told you the problem.

I would suggest strongly that you look into that before fixing the bug so you know how to do this correctly for all of your code.

> jclass manager = env->FindClass("com/jnitester/MainClass");

The var 'manager' is a class variable - it represents a java class.

> public void DoSomething()

This is an instance method - it requires an instance of a class to run.

> env->CallVoidMethod(manager, loadcl_mid);

This method requires a value that represents an instance not a class.

jschella at 2007-7-12 1:20:13 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
Thank you jschellI surely was overlooking the need to creat a jobject first. I appreciate your response.PD
powerdroida at 2007-7-12 1:20:13 > top of Java-index,Java HotSpot Virtual Machine,Specifications...