IOException无法解决为类型错误 [英] IOException can not be resolved to a type error

查看:127
本文介绍了IOException无法解决为类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Java的最终结业,我们在测试中包含try,catch和finally调用的例外部分。当我尝试将示例代码放入Eclipse时,遇到了错误并抛出了新的领域。所有错误都显示无法解析键入。



如何解决此问题,以便我可以学习/查看代码应该做什么? / p>

Q4类

  public static void main(String [] args) 
{
Q4Exception q1 =新的Q4Exception();

try {
q1.sampleMethod();

try {
q1.sampleMethod();
}
//此捕获不会引发错误
catch(RuntimeException es)
{
System.out.println( A);
}
//此下面的catch引发无法解决类型为
catch(IOException es)
{
System.out.println( B );
}
//此捕获不会引发错误
catch(异常e)
{
System.out.println( C);
}
最终{
System.out.println( D);
}

} catch(异常e)
{
System.out.println( E);
}
最终{
System.out.println( F);
}
}

Q4Exception类

  public void sampleMethod()抛出异常
{
try {
throw new IOException( H​​);
}
catch(IOException err)
{
System.out.println( I);
抛出新的RuntimeException( J);
}
catch(异常e)
{
System.out.println(e.toString());
System.out.println( K);
throw new Exception( L);
}
catch(Throwable t)
{
System.out.println( M);
}
最终{
System.out.println( N);
}
}


解决方案

我认为值得一提的是,在Eclipse中,Ctrl + Shif + O可以为您解决导入问题。


For my final in Java we have a "exceptions" part on the test with try, catch, and finally calls. When I try to put the example code into Eclipse I get errors in the catch and throw new areas. All of the errors say "Can not be resolved to type".

How do I fix this so I can learn/review what the code is supposed to be doing?

Q4 Class

public static void main(String [] args) 
 { 
 Q4Exception q1 = new Q4Exception(); 

 try{ 
 q1.sampleMethod(); 

 try{ 
 q1.sampleMethod(); 
 }
 //This catch does not throw an error 
 catch(RuntimeException es) 
 { 
 System.out.println("A"); 
 }
 //This catch below throws the error of cannot be resolved to a type 
 catch(IOException es) 
 { 
 System.out.println("B"); 
 }
 //This catch does not throw an error 
 catch(Exception e) 
 { 
 System.out.println("C"); 
 } 
 finally{ 
 System.out.println("D"); 
 } 

 }catch(Exception e) 
 { 
 System.out.println("E"); 
 } 
 finally{ 
 System.out.println("F"); 
 } 
 }

Q4Exception Class

public void sampleMethod() throws Exception 
 { 
 try{ 
 throw new IOException("H"); 
 } 
 catch(IOException err) 
 { 
 System.out.println("I"); 
 throw new RuntimeException("J"); 
 } 
 catch(Exception e) 
 { 
 System.out.println(e.toString()); 
 System.out.println("K"); 
 throw new Exception("L"); 
 } 
 catch(Throwable t) 
 { 
 System.out.println("M"); 
 } 
 finally{ 
 System.out.println("N"); 
 } 
 } 

解决方案

I think it's worth mentioning that in Eclipse, Ctrl+Shif+O does the job of resolving the imports for you.

这篇关于IOException无法解决为类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆