1.报错:
Access restriction:The type JPEGCodec is not accessible due to restriction on required library E:\Java\JDK\jre\lib\rt.jar
解决方法:
Project -> Properties -> libraries -> Add External JARS…,
先remove掉JRE System Library,然后再Add Library重新加入。
2.修改字体,背景,显示行号等设置
window -> Prefenences -> General -> Text Editors/color and fonts ->basic
3.Sring类型使用双引号
String a = "4";//否则报错:Type mismatch:connot convert from char to String
String类在java.lang.String里,这个包在rt.jar里 ->E:\JAVA\JDK\jre\lib
如果遇到无法解析问题,先 Project -> clean…重启一下,此步骤作用在于 将之前那生成的.class文件删除,重新编译。
Project -> properties -> Java Build Path ->Libraries 补充jar包
4.eclipse查看类源码失败:Class File Editor, source not found…
点击Attached Source…按钮,添加JDK文件下的src.zip,OK
src.zip文件:存放的是JDK源码
lib :存 jar包
include :头文件
bin :Java编译器(javac.exe),虚拟机
5.Java中使用System.out.printf()报错:The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, long)……
解决:
project -> properties ->java compiler,将版本改为1.5及以上的,1.5以下的不支持
6.java.lang.NullPointerException
空指针异常,对象为空,却调用了它的方法
7.The method println(boolean) in the type PrintStream is not applicable for the arguments (void)//在调用setCharAt()时遇到的
解决
大概意思是,我调用的方法返回值是void,而我调用的println给的是个boolean的。
查看setCharAt源码,setCharAt()的返回值类型是一个void。setCharAt()没有返回值,所以不能打印。可以先执行str.setCharAt(2,‘A’);在执行System.out.println(str);