ERROR: JDWP Unable to get JNI 1.2 environment

package com.dhys;

import java.util.Date;

import com.dhys.hourse3.util.House3Util;

public class T {
    public static void main(String[] args) {
        Date now = new Date();
        String string = House3Util.dateToString(now);
        int hour = Integer.parseInt(string.substring(11, 13));
        int minute = Integer.parseInt(string.substring(14, 16));
        int seconds = Integer.parseInt(string.substring(17, 19));
        System.out.println("小时:" + hour + ";分钟" + minute + ";秒:" + seconds);
        long time = hour * 3600 + minute * 60 + seconds;
        //
        if (((7 * 3600 + 30 * 60) < time && time < (9 * 3600))
            || ((11 * 3600 + 30 * 60) < time && time < (13 * 3600 + 30 * 60))
            || ((17 * 3600 + 30 * 60) < time && time < (19 * 3600)))
            return;
        System.out.println("1");
       
    }
}

 

debug模式:输入结果如下:

小时:14;分钟26;秒:32
1
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]

问题:run模式:不会出现ERROR;debug模式:

原因:重定向问题

原理:虚拟机是否有一个控制台Console取决于所依赖的平台和虚拟机解析该方法的方式。如果虚拟机是从一个交互式的命令行中启动的,而没有重定向标准输入和输出流,那么虚拟机会自动的连接到键盘作为标准输入,并且把启动虚拟机的地方作为标准输出。

由上可知,这个主要是把启动虚拟机的地方作为标准输出来说是不合适的,这里的Console()返回的默认情况下是Null,于是就产生了上面的出错信息。

解决方案:

在main方法中加入System.exit(0);(退出虚拟机)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值