Java常见错误(总结中)

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);

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值