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 ...
随机推荐
- Ubuntu启动、停止、重新启动MySQL,查看MySQL错误日志、中文编码错误
1)启动: sudo /etc/init.d/mysql start 2)停止: sudo /etc/init.d/mysql stop 3)重新启动: sudo /etc/init.d/mysql ...
- 单例模式 GetInstance()
如何设计一个含GetInstance()函数的类 直接上代码: 头文件(MyClass.h): class CMyClass { public: CMyClass(void); ~CMyClass(v ...
- Win10下Genymotion无法正常使用的解决方法
原Win7下安装配置的genymotion正常使用,Eclipse的Genymotion插件也可以正常运行.系统升级后,忽然就不work了. 折腾了一天试了各种方式,网上的例子也五花八门.最后还是找到 ...
- UISearchBar--改变内部输入框的背景颜色
思路是获取UISearchBar的子视图,判断他是否是输入框(注意不要先入为主地认为是UITextField),最后修改背景色.至于UISearchBar的子视图结构,在不同的iOS版本可能会不一样, ...
- oracle习题SQL语句练习
表(一)Student (学生表) 属性名 数据类型 可否为空 含 义 Sno Varchar2(3) 否 学号(主码) Sname Varchar2(8) 否 学生姓名 Ssex Varchar2( ...
- events模块
/** * Created by Administrator on 2016/8/3. */ var http = require("http"); //Node 导入文件系统模块 ...
- PHP学习遇到的问题
使用php ob_start()模板生成html 内容无法撑开 生成后主要的内容 <body><warp><main> 生成后这个几个节点总是固定大小,不能被内容撑 ...
- IOS 特定于设备的开发:使用加速器启动屏幕上的对象
借助一点编程工作,iPhone的机载加速计就可以使对象在屏幕上四处“移动”,实时响应用户倾斜手机的方式.下面的代码就是创建一个动画式的蝴蝶,用户可以使之快速移过屏幕. 使之工作的秘密在于:向程序中添加 ...
- MySQL 表分区的几种方法和注意
分区方法1:Hash分区 例子: create table thash(x int ,y int) partition by hash(x) partitions 4; 就这么一句话表就分好区了.下一 ...
- Module中引用Module中的Activity时报错了,错误是找不到R文件中的id引用
1.好像库modul和主modul不能有相同名字和layout文件 2.资源文件名冲突导致的