Eclipse报错:ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2

来源:互联网 发布:linux设置脚本开机启动 编辑:程序博客网 时间:2024/05/17 21:52
     今天在实验室调程序遇上Eclipse报这样的错误:
 
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820]
这种情况我肯定不是第一个人遇到,于是网上搜一下,果然早就有人遇到此类问题,网上的描述如下:

经过我仔细的查阅Java Doc,发现其中有这么一段话:

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 virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will 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 will typically not have a console." ">http://download.java.net/jdk6/docs/api/java/io/Con..."

翻译一下:

虚拟机是否有一个控制台Console取决于所依赖的平台和虚拟机解析该方法的方式。如果虚拟机是从一个交互式的命令行中启动的,而没有重定向标准输入和输出流,那么虚拟机会自动的连接到键盘作为标准输入,并且把启动虚拟机的地方作为标准输出。如果虚拟机是自动启动的,例如通过后台的一个任务计划,那么典型的情况就是没有Console控制台……。

于是,思考一下我们运行上面程序的地点——Eclipse等集成开发环境,这对于上面描述中的把启动虚拟机的地方作为标准输出来说是不合适的,这里的Console()返回的默认情况下是Null,于是就产生了上面的出错信息。(也许未来Eclipse会有所改进吧)

怎么解决该问题呢?这里提供两条思路给大家(已经实际操作过,可以实现功能的正常运作)

1、使用命令行进行运行,编译可以使用集成开发环境。这样可以完成标准输出。
2、在程序中重定向标准输出到其他的设备或者方式(例如写到文本文件),这样也可以“比较不方便的”完成该功能。

总结:
重申!!文档很重要,特别是官方文档和一些说明书性质的文献资料。预期看什么XX天精通YY技术,还不如首先把官方的文档通读一遍。推荐Java Doc和MSDN Library。
原创粉丝点击