JNI exceptions thrown

Posted on 2004-05-01
Last Modified: 2013-11-23
I have created a java GUI and built a cpp dll file to be called by the GUI, when I build the machine generated .h file (javah) it creates a file that looks unusual but works, I am trying to collect a machine name, username, password and 3 boolean values in the GUI, and pass them as an object to the dll, if I just call the dll and not pass the object then it works fine, however I tried to pass the object and pull out the attributes then I get very unusual exceptions during runtime, I got the technique for extracting the values from this site:

Here is the javah generated file:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class guineyd_java_ProgramStartup */

#ifndef _Included_guineyd_java_ProgramStartup
#define _Included_guineyd_java_ProgramStartup
#ifdef __cplusplus
extern "C" {
#undef guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_UNKNOWN
#define guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_UNKNOWN 0L
#undef guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_DEFAULT
#define guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_DEFAULT 1L
#undef guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_SET
#define guineyd_java_ProgramStartup_FOCUS_TRAVERSABLE_SET 2L
/* Inaccessible static: focusTraversalKeyPropertyNames */
/* Inaccessible static: LOCK */
/* Inaccessible static: dbg */
/* Inaccessible static: isInc */
/* Inaccessible static: incRate */
#undef guineyd_java_ProgramStartup_TOP_ALIGNMENT
#define guineyd_java_ProgramStartup_TOP_ALIGNMENT 0.0f
#undef guineyd_java_ProgramStartup_CENTER_ALIGNMENT
#define guineyd_java_ProgramStartup_CENTER_ALIGNMENT 0.5f
#undef guineyd_java_ProgramStartup_BOTTOM_ALIGNMENT
#define guineyd_java_ProgramStartup_BOTTOM_ALIGNMENT 1.0f
#undef guineyd_java_ProgramStartup_LEFT_ALIGNMENT
#define guineyd_java_ProgramStartup_LEFT_ALIGNMENT 0.0f
#undef guineyd_java_ProgramStartup_RIGHT_ALIGNMENT
#define guineyd_java_ProgramStartup_RIGHT_ALIGNMENT 1.0f
#undef guineyd_java_ProgramStartup_serialVersionUID
#define guineyd_java_ProgramStartup_serialVersionUID -7644114512714619750i64
/* Inaccessible static: metrics */
/* Inaccessible static: class_00024java_00024awt_00024Component */
/* Inaccessible static: class_00024java_00024awt_00024event_00024ComponentListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024FocusListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024HierarchyListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024HierarchyBoundsListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024KeyListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024MouseListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024MouseMotionListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024MouseWheelListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024InputMethodListener */
/* Inaccessible static: class_00024java_00024beans_00024PropertyChangeListener */
#undef guineyd_java_ProgramStartup_serialVersionUID
#define guineyd_java_ProgramStartup_serialVersionUID 4613797578919906343i64
/* Inaccessible static: dbg */
#undef guineyd_java_ProgramStartup_INCLUDE_SELF
#define guineyd_java_ProgramStartup_INCLUDE_SELF 1L
#undef guineyd_java_ProgramStartup_SEARCH_HEAVYWEIGHTS
#define guineyd_java_ProgramStartup_SEARCH_HEAVYWEIGHTS 1L
/* Inaccessible static: class_00024java_00024awt_00024Container */
/* Inaccessible static: class_00024java_00024awt_00024event_00024ContainerListener */
/* Inaccessible static: class_00024java_00024awt_00024KeyboardFocusManager */
/* Inaccessible static: systemSyncLWRequests */
#undef guineyd_java_ProgramStartup_OPENED
#define guineyd_java_ProgramStartup_OPENED 1L
/* Inaccessible static: nameCounter */
#undef guineyd_java_ProgramStartup_serialVersionUID
#define guineyd_java_ProgramStartup_serialVersionUID 4497834738069338734i64
/* Inaccessible static: dbg */
/* Inaccessible static: class_00024java_00024awt_00024Window */
/* Inaccessible static: class_00024java_00024awt_00024event_00024WindowListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024WindowFocusListener */
/* Inaccessible static: class_00024java_00024awt_00024event_00024WindowStateListener */
#undef guineyd_java_ProgramStartup_DEFAULT_CURSOR
#define guineyd_java_ProgramStartup_DEFAULT_CURSOR 0L
#undef guineyd_java_ProgramStartup_CROSSHAIR_CURSOR
#define guineyd_java_ProgramStartup_CROSSHAIR_CURSOR 1L
#undef guineyd_java_ProgramStartup_TEXT_CURSOR
#define guineyd_java_ProgramStartup_TEXT_CURSOR 2L
#undef guineyd_java_ProgramStartup_WAIT_CURSOR
#define guineyd_java_ProgramStartup_WAIT_CURSOR 3L
#undef guineyd_java_ProgramStartup_SW_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_SW_RESIZE_CURSOR 4L
#undef guineyd_java_ProgramStartup_SE_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_SE_RESIZE_CURSOR 5L
#undef guineyd_java_ProgramStartup_NW_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_NW_RESIZE_CURSOR 6L
#undef guineyd_java_ProgramStartup_NE_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_NE_RESIZE_CURSOR 7L
#undef guineyd_java_ProgramStartup_N_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_N_RESIZE_CURSOR 8L
#undef guineyd_java_ProgramStartup_S_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_S_RESIZE_CURSOR 9L
#undef guineyd_java_ProgramStartup_W_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_W_RESIZE_CURSOR 10L
#undef guineyd_java_ProgramStartup_E_RESIZE_CURSOR
#define guineyd_java_ProgramStartup_E_RESIZE_CURSOR 11L
#undef guineyd_java_ProgramStartup_HAND_CURSOR
#define guineyd_java_ProgramStartup_HAND_CURSOR 12L
#undef guineyd_java_ProgramStartup_MOVE_CURSOR
#define guineyd_java_ProgramStartup_MOVE_CURSOR 13L
#undef guineyd_java_ProgramStartup_NORMAL
#define guineyd_java_ProgramStartup_NORMAL 0L
#undef guineyd_java_ProgramStartup_ICONIFIED
#define guineyd_java_ProgramStartup_ICONIFIED 1L
#undef guineyd_java_ProgramStartup_MAXIMIZED_HORIZ
#define guineyd_java_ProgramStartup_MAXIMIZED_HORIZ 2L
#undef guineyd_java_ProgramStartup_MAXIMIZED_VERT
#define guineyd_java_ProgramStartup_MAXIMIZED_VERT 4L
#undef guineyd_java_ProgramStartup_MAXIMIZED_BOTH
#define guineyd_java_ProgramStartup_MAXIMIZED_BOTH 6L
/* Inaccessible static: nameCounter */
#undef guineyd_java_ProgramStartup_serialVersionUID
#define guineyd_java_ProgramStartup_serialVersionUID 2673458971256075116i64
/* Inaccessible static: class_00024java_00024awt_00024Frame */
#undef guineyd_java_ProgramStartup_EXIT_ON_CLOSE
#define guineyd_java_ProgramStartup_EXIT_ON_CLOSE 3L
/* Inaccessible static: defaultLookAndFeelDecoratedKey */
 * Class:     guineyd_java_ProgramStartup
 * Method:    driver
 * Signature: (Lguineyd/java/ProgramStartup$MachineDetails;)V
JNIEXPORT void JNICALL Java_guineyd_java_ProgramStartup_driver
  (JNIEnv *, jobject, jobject);

#ifdef __cplusplus

I dont know what all the #defines are for, these dont usually appear in the examples on the net.
at the very end of the file above you will see the definition for the native method, which looks OK(appart from all the stuff above it).

Here is the cpp code for reading the object and its attributes, if I get rid of all the code inside the bracket and just run a cpp program like it was a .exe then it works fine.

JNIEXPORT void JNICALL Java_guineyd_java_ProgramStartup_driver
  (JNIEnv * env, jobject obj, jobject jclazz)
static jclass javaMcClass = env->GetObjectClass(jclazz);

static jmethodID mid = env->GetMethodID(javaMcClass, "MachineDetails", "");

static jfieldID fidMcName = env->GetFieldID
      (javaMcClass, "BSTRMachineName", "Ljava/lang/String;");

static jstring javaMcName = (jstring) env->GetObjectField(obj, fidMcName);

static jfieldID fidUName = env->GetFieldID
      (javaMcClass, "UserName", "Ljava/lang/String;");

static jstring javaUserName = (jstring) env->GetObjectField(obj, fidUName);

static jfieldID fidPWord = env->GetFieldID
      (javaMcClass, "PassWd", "Ljava/lang/String;");

static jstring javaPassWd = (jstring) env->GetObjectField(obj, fidPWord);

static jfieldID fidAvailMem = env->GetFieldID
      (javaMcClass, "AvailMemory", "Z");

static jboolean javaAvailMemory = (bool) env->GetObjectField(obj, fidAvailMem);

static jfieldID fidDiskSpace = env->GetFieldID
      (javaMcClass, "DiskSpaceFree", "Z");

static jboolean javaDiskSpaceFree = (bool) env->GetObjectField(obj, fidDiskSpace);

static jfieldID fidLoadPerc = env->GetFieldID
      (javaMcClass, "LoadPercentage", "Z");

static jboolean javaLoadPercentage = (bool) env->GetObjectField(obj, fidLoadPerc);  

and here is what I get when I run the whole app.
I start the java GUI and the JNI is initiated by a buttons event listener,


An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x208

NOTE: We are unable to locate the function name symbol for the error
      just occurred. Please refer to release documentation for possible
      reason and solutions.

Current Java thread:
        at Method)
        at javax.swing.AbstractButton.fireActionPerformed(
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
        at javax.swing.DefaultButtonModel.setPressed(
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
        at java.awt.Component.processMouseEvent(
        at java.awt.Component.processEvent(
        at java.awt.Container.processEvent(
        at java.awt.Component.dispatchEventImpl(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.LightweightDispatcher.retargetMouseEvent(
        at java.awt.LightweightDispatcher.processMouseEvent(

        at java.awt.LightweightDispatcher.dispatchEvent(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Window.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.EventQueue.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
        at java.awt.EventDispatchThread.pumpEvents(

        at java.awt.EventDispatchThread.pumpEvents(


Dynamic libraries:
0x00400000 - 0x00406000         C:\JBuilderX\jdk1.4\bin\java.exe
0x77F80000 - 0x77FFD000         C:\WINNT\system32\ntdll.dll
0x7C2D0000 - 0x7C332000         C:\WINNT\system32\ADVAPI32.dll
0x7C570000 - 0x7C628000         C:\WINNT\system32\KERNEL32.DLL
0x77D30000 - 0x77DA1000         C:\WINNT\system32\RPCRT4.DLL
0x78000000 - 0x78045000         C:\WINNT\system32\MSVCRT.dll
0x08000000 - 0x08136000         C:\JBuilderX\jdk1.4\jre\bin\client\jvm.dll
0x77E10000 - 0x77E75000         C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7E000         C:\WINNT\system32\GDI32.DLL
0x77570000 - 0x775A0000         C:\WINNT\system32\WINMM.dll
0x10000000 - 0x10007000         C:\JBuilderX\jdk1.4\jre\bin\hpi.dll
0x007C0000 - 0x007CE000         C:\JBuilderX\jdk1.4\jre\bin\verify.dll
0x007D0000 - 0x007E8000         C:\JBuilderX\jdk1.4\jre\bin\java.dll
0x007F0000 - 0x007FD000         C:\JBuilderX\jdk1.4\jre\bin\zip.dll
0x18270000 - 0x1837F000         C:\JBuilderX\jdk1.4\jre\bin\awt.dll
0x77800000 - 0x7781E000         C:\WINNT\system32\WINSPOOL.DRV
0x76620000 - 0x76630000         C:\WINNT\system32\MPR.DLL
0x75E60000 - 0x75E7A000         C:\WINNT\system32\IMM32.dll
0x77A50000 - 0x77B3F000         C:\WINNT\system32\ole32.dll
0x18380000 - 0x183D0000         C:\JBuilderX\jdk1.4\jre\bin\fontmanager.dll
0x51000000 - 0x5104B000         C:\WINNT\system32\ddraw.dll
0x728A0000 - 0x728A6000         C:\WINNT\system32\DCIMAN32.dll
0x5C000000 - 0x5C0C7000         C:\WINNT\system32\D3DIM700.DLL
0x20860000 - 0x20890000         C:\COLLEGE\attempt\cpp\guineyd\guineyd.dll
0x779B0000 - 0x77A4B000         C:\WINNT\system32\OLEAUT32.dll
0x20890000 - 0x2094C000         C:\WINNT\system32\MSVCP71D.dll
0x20950000 - 0x209D7000         C:\WINNT\system32\MSVCR71D.dll
0x775A0000 - 0x77630000         C:\WINNT\system32\CLBCATQ.DLL
0x65A60000 - 0x65A6A000         C:\WINNT\System32\wbem\wbemprox.dll
0x65C20000 - 0x65CCD000         C:\WINNT\System32\wbem\wbemcomn.dll
0x77920000 - 0x77943000         C:\WINNT\system32\imagehlp.dll
0x72A00000 - 0x72A2D000         C:\WINNT\system32\DBGHELP.dll
0x690A0000 - 0x690AB000         C:\WINNT\system32\PSAPI.DLL

Heap at VM Abort:
 def new generation   total 576K, used 543K [0x10010000, 0x100b0000, 0x104f0000)

  eden space 512K,  93% used [0x10010000, 0x10087fa0, 0x10090000)
  from space 64K, 100% used [0x100a0000, 0x100b0000, 0x100b0000)
  to   space 64K,   0% used [0x10090000, 0x10090000, 0x100a0000)
 tenured generation   total 1408K, used 129K [0x104f0000, 0x10650000, 0x14010000
   the space 1408K,   9% used [0x104f0000, 0x10510740, 0x10510800, 0x10650000)
 compacting perm gen  total 4352K, used 4224K [0x14010000, 0x14450000, 0x1801000
   the space 4352K,  97% used [0x14010000, 0x14430200, 0x14430200, 0x14450000)

Local Time = Sat May 01 18:38:55 2004
Elapsed Time = 5
# The exception above was detected in native code outside the VM
# Java VM: Java HotSpot(TM) Client VM (1.4.2_01-b06 mixed mode)
# An error report file has been saved as hs_err_pid2492.log.
# Please refer to the file for further information.
Press any key to continue . . .


Any help is realy apreciated
Question by:vassim
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

keteracel earned 500 total points
ID: 10968665
make life easier on yourself... save it to a temporary text file!

Author Comment

ID: 10968677
Well the project says Im supposed to display use of JNI, so I think using a temporary file would be cheating somewhat.

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question