Home > error: jdwp unable to get jni 1.2 environment, jvm->getenv() return code = -2

How to fix the error: "jdwp unable to get jni 1.2 environment, jvm->getenv() return code = -2"?

Alton Alexander
By Alton AlexanderUpdated on June 4th, 2022

The error code -2 indicates that the JNI environment could not be obtained. This can happen if the JNI version is not supported or if the VM is not initialised.

1. Check that the JDK and JRE versions are compatible

  1. Check that the JDK and JRE versions are compatible.
  2. If the JDK and JRE versions are not compatible, then the issue is with the Java platform, and not with the JDK or JRE. Consult the Java platform documentation for instructions on how to fix the issue.

2. Set the environment variable _JAVA_OPTIONS to -Djava.compiler=NONE

The environment variable _JAVA_OPTIONS can be set to -Djava.compiler=NONE in order to try to fix the error: jdwp unable to get jni 1.2 environment, jvm->getenv() return code = -2.

3. Use the -Xnoagent option when starting the JVM

java -Xnoagent

4. Use the -Xdebug and -Xrunjdwp options when starting the JVM

The -Xdebug and -Xrunjdwp options can be used to fix an error that is encountered when starting the JVM. The jdwp unable to get jni 1.2 environment error indicates that the JVM was not able to find a suitable JNI environment. The jvm->getenv() return code indicates the error that was encountered.

5. Set the environment variable JAVA_COMPILER to NONE

  1. Open a command prompt.
  2. Change to the directory where your Java installation is located.
  3. Type the following command: setenv JAVA_COMPILER NONE
  4. Close the command prompt.

If you didn't find success with an option above, then try:

  1. Use the -Xnojvm option when starting the JVM.