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

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


问题描述

在 Eclipse 中用 debug 模式调试远程执行 Linux 命令的代码报错:

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]

问题原因

查阅 Java Doc,发现其中有这么一段话:

“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.”

译文如下:

虚拟机是否有一个控制台取决于所依赖的平台和调用虚拟机的方式,如果虚拟机是从一个交互式的命令行中启动的,而没有重定向标准输入和输出流,那么虚拟机将会有个控制台,并且通常会连接到启动虚拟机的平台的键盘和显示器上;如果虚拟机是自动启动的,如通过后台的一个任务调度,那么通常这种情况是没有控制台的。

而调试远程执行 Linux 命令后会将结果输出,而上一次调试时程序有报错,进程没有正常退出。

这个错误的原因是上次启动调试的代码有错误,导致进程没有终止,占用了 Console 输出,所以在之后又启动调试的时候才会出现此错误。

解决方法

在调用方法结束时,添加 system.exit(0);

System.exit(0); 会使程序立即被终止,如果程序中有线程还在执行任务,则后续的任务也就无法继续执行了。




参考文章:
http://www.cnblogs.com/duffy/p/4612619.html
http://blog.csdn.net/testcs_dn/article/details/42677269

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值