ERROR:JDWP unable to get JNI 1.2 environment, JVM->GETENV () Return code =-2

Source: Internet
Author: User
Tags finally block
Reproduced from: http://blog.csdn.net/mmllkkjj/article/details/6149043

ERROR:JDWP unable to get JNI 1.2 environment, JVM->GETENV () Return code =-2

This morning began compiling a small example of the book. It is strange to find this error, because it is OK to compile directly with JDK, but if you compile with eclipse, this error will occur, but you can also generate the. class file and the output of the console is normal.
I use the following example:
public class Countinstances {
private static int numinstances = 0;
protected static int getnuminstances () {
return numinstances;
}
private static void Addinstance () {
numinstances++;
}
Countinstances () {
Countinstances.addinstance ();
}
public static void Main (string[] arguments) {
System.out.println ("Starting with" +
Countinstances.getnuminstances () + "instances");
for (int i = 0; i < ++i)
New Countinstances ();
System.out.println ("Created" +
Countinstances.getnuminstances () + "instances");
}
}
The internet searched for the reason: Eclipse and jdk1.6 version of the conflict Sun's Web site has http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6476706 is not yet resolved.
Also found a wonderful comment, as follows:
After I looked over the Java Doc carefully, I found this passage:
Http://download.java.net/jdk6/docs/api/java/io/Console.html
"Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the V Irtual machine is invoked. If the virtual machine is started from a interactive command line without redirecting the standard input and output Strea Ms then its console would exist and would typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it'll typically not hav e a console. " ">http://download.java.net/jdk6/docs/api/java/io/con ..."
Translation:
Whether a virtual machine has a console console depends on how the platform and the virtual machine on which they are dependent resolve the method. If the virtual machine is started from an interactive command line without redirecting standard input and output streams, the virtual opportunity is automatically connected to the keyboard as standard input, and the place where the virtual machine is started is used as standard output. If the virtual machine is started automatically, for example through a task plan in the background, then the typical situation is that there is no console console ....
So, consider the integrated development environment where we run the above program,--eclipse, which is not appropriate for the place where the virtual machine was launched as standard output, where console () returned by default is null, resulting in the error message above. (maybe eclipse will improve in the future.)
How to solve the problem. Here are two ideas for everyone (already in operation, can realize the function of the normal operation)
1, use the command line to run, the compilation can use the integrated development environment. This will complete the standard output.
2, in the program to redirect the standard output to other devices or methods (such as writing to a text file), this can also be "more inconvenient" to complete the function.
Summarize:
Reiterated.. Documents are important, especially in official documents and in the nature of some brochures. Expected to see what xx days proficient in YY technology, but also as the first official document read through. The Java Doc and MSDN Library are recommended.
It seems to have found the problem, but there is also a Netizen's method is to add a system.exit (0) behind the main function;
Sure enough, but that's why. System.exit (0) What is the difference in return, you have to check on the Internet:
It is said that System.exit (0) is used to abort multiple threads, that is, all threads generated by this program will be aborted. But I still can't figure out what it does in this procedure. The following explanations for System.exit (0) are worth referring to.
Return and System.exit (0) different [paste]
If I am in public static void main (string[] args)
One line of code plus return; will cause the JVM to skip main ()
Which is the end of the program, ask and write System.exit (0) What is the difference?
Because you return in public static void main (string[] args) ...
So the effect is equivalent to System.exit () ...
But just leave this method ...
That would obviously be different ....
Maybe it can be said ...
Return => to the upper layer ...
System.exit () => back to the upper layer ...

System.exit (0) should be an instruction in the JVM.
Even after finally block encountered System.exit (0) There is no way to continue to execute the
From System.exit (), the actual parameters, regardless of their value, are eventually ended,
But this value can be captured by the program that calls it. For example, we can write a batch file in Windows,
To execute the program, when the program is executed or interrupted, the exit () 's parameters are spread out,
And then we can judge the errorlevel (the spread of the value will be placed in this variable) to decide what to do next
Up.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.