Java IOException 无法解析为类型错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20551475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:44:15  来源:igfitidea点击:

IOException can not be resolved to a type error

javaexceptiontry-catch

提问by Cow

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".

对于我的 Java 期末考试,我们在测试中有一个“异常”部分,包括 try、catch 和 finally 调用。当我尝试将示例代码放入 Eclipse 时,我在 catch 中遇到错误并抛出新区域。所有错误都说“无法解析输入”。

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

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

Q4 Class

Q4班

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

Q4Exception 类

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

采纳答案by Felipe Martins Melo

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

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

回答by Cow

Oh, guess I could answer my own question here. Didn't know I had to import the IOException from java.io!

哦,我想我可以在这里回答我自己的问题。不知道我必须从 java.io 导入 IOException!

回答by Dan Cartier

Easy to just use

易于使用

import java.io.*

for the imports

对于进口

回答by Osama Al-Banna

I discovered I was using an old version of JWT , the issue is gone after using the a newer version of JWT dependency .

我发现我使用的是旧版本的 JWT,使用较新版本的 JWT 依赖项后问题消失了。