[英]Access violation calling a native (C++) function from Java using JNI: Is this an issue with my code, or a known issue?
[英]Error Calling a Java Method From Native C++ Using JNI (ACCESS_VIOLATION error)
我遇到了一個問題:我嘗試調用一個應該在控制台中打印的java方法。 它是使用JNI從C ++本機dll調用的。 問題是它不起作用,我得到了這個錯誤:
#
# 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
#
這是我用來調用一個簡單的java方法的C ++代碼,它將在控制台中打印一行:
jclass jTablObjClass = env->FindClass("MainFrame/Jni/TablesObjects"); // get jclass
jmethodID printMethId = env->GetMethodID(jTablObjClass, "print", "()V"); // get jmethod
env->CallVoidMethod(jTablObjClass, printMethId); // call jmethod
請幫忙 ! ^^
哦,剛才意識到。 您正在調用CallVoidMethod
但第一個參數是一個類。 如果方法是靜態的,則應該使用GetStaticMethodID
和CallStaticVoidMethod
,如果方法不是靜態的,則應該給出一個對象實例,而不是一個類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.