0

I got a problem : I try to call a java method that's supposed to print something in the console. It is called from a C++ native dll using JNI. The problem is that it won't work and I get that error :

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6c5f5253, pid=4472, tid=4956
#
# JRE version: 6.0_29-b11
# Java VM: Java HotSpot(TM) Client VM (20.4-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  0x6c5f5253
#
# An error report file with more information is saved as:
# C:\location\MyApp\hs_err_pid4472.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

Here is the C++ code I use to call a simple java method that will print a row in console :

jclass jTablObjClass = env->FindClass("MainFrame/Jni/TablesObjects");           // get jclass   
jmethodID printMethId = env->GetMethodID(jTablObjClass, "print", "()V");        // get jmethod
env->CallVoidMethod(jTablObjClass, printMethId);                                // call jmethod

Please, help ! ^^

7
  • 1
    Add return value checks to find out precise place of failure. Check all return values if they are not null. Commented Nov 21, 2011 at 10:08
  • In fact, the source of the crash is the call of the void java method env->CallVoidMethod(jTablObjClass, printMethId); But there's actually no reason for it to crash so ... Commented Nov 21, 2011 at 10:16
  • 1
    jTablObjClass and printMethId are not null? Commented Nov 21, 2011 at 10:19
  • How could I check that plz ? Is there a function I should use ? Commented Nov 21, 2011 at 10:24
  • if(jTablObjClass == NULL) {report an error and do something} Commented Nov 21, 2011 at 10:25

1 Answer 1

2

Oh, just realized. You are calling CallVoidMethod but the first argument is a class. If the method is a static, you should use GetStaticMethodID and CallStaticVoidMethod, if the method is not static, you should give an object instance, not a class.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much ! You are great! I tried to set my java method "static" and in my native c++ code, I call the GetStaticMethodID and then the CallStaticVoidMethod and it actually did work out ! ^^ So thank you so much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.