77

I get this error after debugging in Eclipse. The debug is successful though.

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820]

What does it mean?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Carlos Blanco
  • 8,592
  • 17
  • 71
  • 101
  • I face the exact same problem from within NetBeans 6.1 when attempting to debug into a piece of code that uses both the network, and image API. Were you trying to use either the network, or image API by any chance? – Everyone Apr 15 '11 at 13:15
  • I was not using the Image API, for sure. What do you mean by using the network? I was using sockets if that's what you mean. – Carlos Blanco Apr 15 '11 at 13:38
  • Yep; network APIs is what i meant - Sockets/Http – Everyone Apr 15 '11 at 16:14

6 Answers6

81

Just add System.exit(0); to the end of your main method.

That's all you have to do.

Quackers
  • 25
  • 9
Vasile Surdu
  • 1,203
  • 1
  • 10
  • 11
39

Looks like http://bugs.sun.com/view_bug.do?bug_id=6476706 which has low priority and is still not fixed. Definitely a Mustang bug but no clear explanation (seems to occur pretty randomly according to the bug reporters on top of that).

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
5

It's apparently a JVM bug. It's harmless and unpredictable.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
3

Happens on something as simple as this tutorial

//trim spaces
String s2 = "Welcome!";
int len1 = s2.length();
System.out.println(len1);
String s3 = s2.trim();
System.out.println(s3.length());

Happens if run program too fast multiple times so something to do with system performance?

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:838]
Kartik Chugh
  • 1,104
  • 14
  • 28
Ian
  • 31
  • 1
0

@Everyone I'm facing this problem using the image API reading and writing files over the network, when I run the program working with local files this doesn't happen. After verifiying my results I confirmed that it really doesn't do any harm (at least on my debugging). Now that I'm reading this post I stopped looking into it.

CocheLee
  • 121
  • 8
0

I have noticed this occurs when I am using a workspace stored on my USB drive and sometimes on my work's network. It is not a major issue and doesnt seem to have any effect on the execution of any of my programs. I tested @Vasile Surdu's solution of addingSystem.exit(0); to the end of the main method and it works. Another solution is to restart eclipse which works for me most of the time.

Adil Ras
  • 5
  • 3