常见的异常问题以及解决办法

1.源代码:[System.out.prntln("系统出现未知错误,请找程序员解决");]

   错误:The method prinln(String) is undefined for the type PrintStream

   解析:该方法prinln(字符串)是未定义的类型PrintStream

   解决办法:将打印语句中的prinln属于拼写错误,修改代码为正确的println

2. 源代码:Test test[]=new Test[];

   错误:Variable must provide either dimension expressions or an array initializer

   解析:变量必须提供尺寸表达式或数组的初始化    

   解决办法:规定数组的长度

3. 源代码:String name="zhang"

   错误:Syntax error,insert ";" tocomplete BlockStatements
 
   解析:语法错误,插入;完整语句块

   解决办法:语句不完整,添加分号

4. 错误:Return type for the method is missing

   解析:方法缺失了返回类型

   解决办法:在此方法上添加返回值类型或规定它为void

5. 源代码:String="wang";

   错误:String cannot be resolved to a variable

   解析:不能将字符串解析为变量

   解决办法:重新给定类型为String的变量的变量名

6. 错误:The public type SixExceptions must be defined in its own file

   解析:公开类SixExceptions必须要定义在它自己的文件中

   解决办法: 将类名与文件名同名

7. 源代码:List<String> list=new ArrayList<String>();

       list.add(1);

   错误:The method add(int, String) in the type List<String> is not  applicable for the arguments (int)

   解析:异常名字:该方法只能添加(int,string)在类型列表<字符串>不适用于参数(int)
 
   解决办法:在列表list中只填加String型数据

8. 源代码:name();

   错误:The method name() is undefined for the type Zuoye  

   解析:name()这个方法没有定义

   解决办法:先定以这个方法再来调用

9. 源代码:List list=new Array();

   错误:Array cannot be resolved to a type

   解析 :Array没有类型

   解决办法:相应数组添加类型

10.错误:The left-hand side of an assignment must be a variable

   解析:左手边的一个任务必须是一个变量
 
   解决办法:要在任务的左边放变量 如if(a==1)

11.源代码:int num={1,2,3};

   错误:Type mismatch: cannot convert from int[] to int  

   解析:类型错配,应转化为int[]

   解决办法:缺少了[ ] 将它添加到int后面

12.代码:Properties properties=new Properties();

   错误:Properties cannot be resolved to a type

   解析:属性不能被解析为一个类型

   解决办法:导入Properties

13.错误:Syntax error, insert ")" to complete VariableInitializer

   解析:语法错误,插入“)”使VariableInitializer完整
h
   解决方法:加括号

14.源代码:int a=1.110  

   错误:Type mismatch: cannot convert from double to int  

   解析:类型错配,不能从double到int

   解决办法:如果确定a的类型为int则改变a的值 如果确定a的值要1.110那么改变a的类型

15.错误:Cannot instantiate the type AbstractClass
 
   解析:不能实例化抽象类

   解决办法:不实例化它

16.错误:ArrayList<ETcass> cannot be resolved to a type

   解析:ArrayList < ETass >不能决定一个类型

   解决办法:修改集合泛型

17.代码:BBException b=new ErrorTest();

   错误:Type mismatch: cannot convert from ErrorTest to BBException

   解析:类型不匹配:不能从errortest到bbexception

   解决办法:让ErrorTest继承BBException

18.错误:The type ErrorTest is already defined

   解析:errortest已定义

   解决办法:改变类名

19.代码:while(true){}break;

   错误:Unreachable code

   解析:执行不到的代码

   解决办法:break 放在无限循环里面

20.错误:break cannot be used outside of a loop or a switch

   解析:break不能用在循环外面(打破不能作为一个环或开关外使用)

   解决办法:查看是否将break放错位置 或去掉break

21.错误:abstract methods do not specify(指定) a body    

   解析;抽象方法不能指定方法体

   解决办法:去掉方法体

22.错误:The local variable i may not have been initialized(初始化)  

   解析: 局部变量i没有初始化

   解决办法:将局部变量初始化

23.错误:The literal 11111111111111111 of type int is out of range

   解析:值超出类型int的范围
 
   解决办法:换种范围更大的类型 或是改变值的大小到int范围内

24.错误:Syntax error on token "throw", throws expected

   解析:语法错误 在“throw”上,应为throws

   解决办法:改为throws

25.错误:The declared package "com.easytopit" does not match the expected package "com.easytopit.map"

   解析:声明包路径不符合预期包路径

   解决办法: 修改包路径为正确路径

26.错误:This method must return a result of type String[]

   解析:这个方法必须返回一字符串数组类型的结果

   解决办法:return结果

27.错误:Type mismatch: cannot convert from Object to Person
 
   解析:类型不匹配:不能用Person声明object

   解决办法:将Object强转为Person

28.错误:The type SvpList must implement the inherited abstract method Comparable<T>.compareTo(T)    
 
   解析:类SvpList必须要实现继承抽象方法Comparable<T>.compareTo(T)

   解决办法:实现接口里面的抽象方法

29.错误:The public type A must be defined in its own file

   解析:公众类型必须在自己的文件中定义的 (一个类里面有两个public类)

   解决办法:一个public类一个文件

30.错误:Cannot use this in a static context(环境)

   解析:不能在静态环境中使用this
 
   解决办法:去除this





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值