title: Creating new objects in JNI
body: <p>I've been creating some code in JNI and most of it is working fine but I haven't been able to create an instance of a Java object from C++ as my Java IDE gives me the following error:</p>
  
  <blockquote>
    <p>A fatal error has been detected by the Java Runtime Environment:</p>
    
    <p>EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000070e1e0d2, pid=10100, tid=0x0000000000000d90</p>
    
    <p>JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
    Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops)
    Problematic frame:
    V  [jvm.dll+0x15e0d2]</p>
    
    <p>Failed to write core dump. Minidumps are not enabled by default on client versions of Windows</p>
    
    <p>An error report file with more information is saved as:
    C:\Users\Alienware\Documents\Netbeans Projects\NativeTest\hs_err_pid10100.log</p>
    
    <p>If you would like to submit a bug report, please visit:
    <a href="http://bugreport.java.com/bugreport/crash.jsp" rel="nofollow noreferrer">http://bugreport.java.com/bugreport/crash.jsp</a></p>
  </blockquote>
  
  <p>The Java object I'm trying to create is:</p>
  
  <pre><code>public class ConstructorObject {    
      public ConstructorObject() {
          System.out.println("Hello World!");
      }
  }
  </code></pre>
  
  <p>and the native class is:</p>
  
  <pre><code>public class NativeNewObject
  {
      static {
          System.loadLibrary("NativeLibrary");
      }
  
      private native void callConstructorObject0();
  
      public void callConstrtuctorObject() {
          callConstructorObject0();
      }
  }
  </code></pre>
  
  <p>The C++ code is:</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_main_NativeNewObject_callConstructorObject0(JNIEnv *e, jobject obj) {
      jclass c = e-&gt;FindClass("ConstructorObject");
      jmethodID mid = e-&gt;GetMethodID(c, "&lt;init&gt;", "()V");
      jobject newObj = e-&gt;NewObject(c, mid);
  }
  </code></pre>
  
  <p>Thanks.</p>