Ошибка получения значения хэш-карты из c ++ с использованием JNI из java - PullRequest
0 голосов
/ 31 января 2020

Я создал класс hashmap, который содержит подробную информацию об имени процесса, идентификаторе и его использовании, и, используя класс hashntry, я сохранил значения для каждой таблицы [i]. Проблема в том, что я могу получить доступ к классу HASHMAP, не могу go возникла ошибка HASHENTRY.

Мой NATIVE-код в CPlusPlus:

//ProcessManagement.h

JNIEXPORT void JNICALL Java_newjni_JNITest_sayHello (JNIEnv*, jobject)
{
    printf("HelloWorld\n");
    HashMap hash;
    int x = hash.get(3);
    printf("%d", x);
    return;
}


 // ProcessInfo.h

 // In hashmapentry class
 .
 .
 .
   HashEntry(int ke, int valu, string nam, int memusag, int cpuusag, double 
    diskusag, double netusag, string unam) {

    this->key = ke;

    this->value = valu;

    this->name = nam;

    this->memusage = memusag;

    this->cpuusage = cpuusag;

    this->diskusage = diskusag;

    this->netusage= netusag;

    this->uname= unam;
  }


   //In hashMap class
   .
   .
   .
     void put(int ke, int valu, string nam, int memusag, int cpuusag, double 
     diskusag, double netusag, string use) {

    int hash = ke;

    table[hash] = new HashEntry(ke, valu, nam, memusag, cpuusag, diskusag, 
    netusag, use);

    }






  //ProcessManagement.cpp
  .
  .
  //used windows api to get values of process

   hash.put(i, (int)pid[i], pname, memusage, cpuusage[i], diskusage, netusage, 
   s);

  .
  .
  .

В JAVA:

 public class JNITest {  // Save as HelloJNI.java
 static {
    System.loadLibrary("ProcessHash"); 

}


 private native void sayHello();
 private native void print();


 public static void main(String[] args) {

    new JNITest().sayHello();  // Create an instance and invoke the native method
 }
 }

И у меня возникает ошибка:

#
# A fatal error has been detected by the Java Runtime Environment:
#
 #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffcf33417dd, pid=12584, tid=4912
#
# JRE version: 6.0_32-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.7-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [ProcessHash.dll+0x217dd]
#
# An error report file with more information is saved as:
# C:\Users\MrBean\Documents\NetBeansProjects\newJNI\hs_err_pid12584.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
HelloWorld

ЖУРНАЛ ОШИБКИ: https://textsaver.flap.tv/lists/356y

...