Jsncrdnl
Jsncrdnl

Reputation: 3075

Error Calling a Java Method From Native C++ Using JNI (ACCESS_VIOLATION error)

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 ! ^^

Upvotes: 0

Views: 1604

Answers (1)

kan
kan

Reputation: 28951

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.

Upvotes: 2

Related Questions