eclipse编译错误
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]
网上查了下
出错原因:装了JDK1.6.0
查阅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控制台......。
解决方法:
1、使用命令行进行运行,编译可以使用集成开发环境。这样可以完成标准输出。
2、在程序中重定向标准输出到其他的设备或者方式(例如写到文本文件),这样也可以"比较不方便的"完成该功能。
这2种方法我没试过,其实我对这个故障描述也不是很懂。但是我用过2种方法可以解决。
3:卸载JDK1.6.0,装1.5.0或者以下版本。
4:在main函数后面加个System.exit(0); 这个问题就可以解决。但是我不知道为什么加了这句话就可以解决了。我理解的这句话的意思是main程序退出时返回0,经过我的试验,发现其实你返回多少都不影响,你可以退出时返回1,2,3,都可以,参照网上的资料,Console()返回的默认情况下是Null,于是就产生了上面的出错信息。那么也就是说只要控制台返回的不是null,那么就不会出错了。应该是这样理解吧,^_^
补充:第4个方法是有问题的,在有些程序中,加了这句和不加的结果是有区别的。比如在下面的这个关于Thread的程序中
public class Example9_2 {
public static void main(String[] args) {
People teacher,student;
ComputerSum sum = new ComputerSum();
teacher = new People("老师",200,sum);
student = new People("学生",200,sum);
teacher.start();
student.start();
}
}
class ComputerSum
{
int sum;
public void setSum(int n)
{
sum=n;
}
public int getSum()
{
return sum;
}
}
class People extends Thread
{
int timeLength; //线程休眠的时间长度
ComputerSum sum;
People(String s,int timeLength,ComputerSum sum)
{
setName(s); //Thread类的方法setName()
this.timeLength=timeLength;
this.sum= sum;
}
public void run()
{
for(int i=1;i<=5;i++)
{
int m=sum.getSum();
sum.setSum(m+1);
System.out.println("我是"+getName()+",现在的和:"+sum.getSum());
try{
sleep(timeLength);
}
catch(InterruptedException e){}
}
}
}
如果不加System.exit(0);那么结果没有什么问题。但是如果加上这句话,结果就变成了
我是老师,现在的和:1
我是学生,现在的和:2
也就是说老师和学生的线程都只分别执行了一次就退出了。所以解决此编译错误用此方法是不大可行的。
由于此debug错误不影响编译,因此还是没什么太大问题。而且如果不debug直接点run,此错误是不会出现的。
eclipse编译错误的更多相关文章
- 怎么在eclipse中查到这个类用的是哪个jar的类和Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案
找到了一个办法,你先按F3,然后点击Change Attached Source..按钮,在弹出的框里有个路径,我的路径是D:/SNFWorkSpace/JAR/~importu9.jar,然后你去引 ...
- Eclipse 编译错误 Access restriction: The type 'JPEGCodec' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')
解决方案: Project -> Properties ->Java Build Path -> libraries, 先 remove 掉 JRE ...
- Eclipse 编译错误 Access restriction:The type *** is not accessible due to restriction on... 解决方案
报错: Access restriction:The type JPEGCodec is not accessible due to restriction on required library C ...
- eclipse NoClassDefFoundError错误
问题描述:eclipse中执行一个java web项目,代码中依赖都是正常的,发布到tomcat中调试就提示NoClassDefFoundError错误, 问题分析:首先确定工程中该类确实存在,因为代 ...
- Java,AWTUtilities,eclipse报编译错误:Access restriction: The type 'AWTUtilities' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')
[场景]调用com.sun.awt.AWTUtilities时,eclipse提示编译错误: Access restriction: The type 'AWTUtilities' is not AP ...
- Eclipse Xml编译错误Referenced file contains errors - spring-beans-4.0.xsd
本文转自:http://josh-persistence.iteye.com/blog/2125420 在eclipse中,有时候在xml文件中,特别是于Spring相关的配置文件中,会出现一些不影响 ...
- eclipse 编译android程序 编译错误
windows->show view -> problems, 这个窗口的内容即为 编译错误的内容.
- 菜鸟调错(八)—— Maven编译错误:不兼容的类型的解决方案
泛型在实际的工作中应用非常广泛,关于泛型就不在这里赘述了,感兴趣请戳<重新认识泛型>.项目中用到了如下的泛型: public <T> T query(String sql, R ...
- 【xml 报错】xml编译错误
---恢复内容开始--- 有时候在xml文件中,特别是于Spring相关的配置文件中,会出现一些不影响程序正常运行的编译错误,如: Referenced file contains errors (h ...
随机推荐
- 每个页面的Title样式
<style>.zc_lan14 {}{ TEXT-ALIGN: center; FONT-FAMILY: "微软雅黑"; MARGIN-BOTTOM: 3px; ...
- MATLAB中为控件(uicontrol)绑定Callback函数(回调函数)
笔者走了许多弯路,终于找到这个方法,分享给大家. 'callback',@(~,~)colormapeditor(h) 如果版本老不支持“~”这种写法,那就改成: 'callback',@(x,y)c ...
- Svn服务启动的两种方式
一.svn服务器启动 cmd命令行启动:vsvnserve -d –r 文档仓库路径 -d 后台执行 -r 版本库的根目录 二.Windows服务自动启动 利用xp.2000 以上的 ...
- Android 汉字转拼音之工具篇
/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Versi ...
- 获取新浪天气api显示天气情况(转)
直接上一个html的demo <!doctype html> <html class="no-js fixed-layout"> <head> ...
- 一个原生js写的加减乘除运算
根据我的经验我说的再多也没人看,不过还是简单介绍下效果吧,可以选择+,-,*,/,去计算数据,喜欢的话就粘贴复制自己看去吧! <!DOCTYPE html PUBLIC "-//W3C ...
- [LeetCode]题解(python):145-Binary Tree Postorder Traversal
题目来源: https://leetcode.com/problems/binary-tree-postorder-traversal/ 题意分析: 后序遍历一棵树,递归的方法很简单,尝试用非递归的方 ...
- .NET(C#):XML序列化时派生类的处理
原文 www.cnblogs.com/mgen/archive/2011/12/03/2275014.html 目录 1. 针对基类的XmlSerializer序列化派生类 2. 类内成员是派生类的序 ...
- 关于oracle spfile配置文件问题
$ORACLE_SID决定spfile dbs 默认 在启动Oracle数据库时报错,如下: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: R ...
- oralce dg conf
http://wenku.baidu.com/view/ea9fa16cdd36a32d73758168.html http://ylw6006.blog.51cto.com/470441/84181 ...