错误:未处理的异常类型IOException.
File imgLoc = new File("player.png");
BufferedImage img = ImageIO.read(imgLoc);
Run Code Online (Sandbox Code Playgroud)
如何从文件位置获取bufferedImage?
我知道我在这里做了一些非常错误的事情,但我会坦白地说,我对java的了解非常薄弱.每当我调用dataIn.readLine()时,我都会收到此编译时错误
unreported exception java.io.IOException; must be caught or declared to be thrown
Run Code Online (Sandbox Code Playgroud)
这是代码,我知道命名约定很糟糕,它几乎什么都不做.
import java.io.*;
public class money {
public static void main( String[]args ){
String quarters;
String dimes;
String nickels;
String pennies;
int iquarters;
int idimes;
int inickels;
int ipennies;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
System.out.println( "Enter the number of quarters. " );
quarters = dataIn.readLine();
System.out.println( "Enter the number of dimes" );
dimes = dataIn.readLine();
System.out.println( "Enter the number of nickels" );
nickels = dataIn.readLine();
System.out.println( "Enter …Run Code Online (Sandbox Code Playgroud) 这是堆栈跟踪:
java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:433)
at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:324)
at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1179)
at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
at javazoom.jlgui.basicplayer.BasicPlayer.open(Unknown Source)
at BasicPlayerDemo.play(BasicPlayerDemo.java:49)
at BasicPlayerDemo.main(BasicPlayerDemo.java:24)
Run Code Online (Sandbox Code Playgroud)
似乎其他人也有这个问题:
有什么理由吗?我正在尝试使用JavaZoom类创建一个简单的Java Swing音乐播放器.
当我运行我的android项目时,我的一个用于地理编码的类显示了一个io异常,比如服务不可用我找不到这里的错误,请有人帮我解决这个问题
我的课
String addressInput = "Santa Clara";
geocoder = new Geocoder(Find_Tab_MainActivity.this);
List<Address> address;
address = geocoder.getFromLocationName(addressInput,5);
if (address == null) {
alert.showAlertDialog(Find_Tab_MainActivity.this, "Places Error",
"Sorry error occured.",
false);
}
else{
Address location = address.get(0);
latitude = location.getLatitude();
longitude = location.getLongitude();
System.out.println("radius:");
nearPlaces = googlePlaces.Keywordsearch(latitude,longitude,radius+40000,"parking",type);
Run Code Online (Sandbox Code Playgroud)
logcat的
03-07 12:55:09.752: D/Your Location(3625): latitude:37.422005, longitude: -122.084095
03-07 12:55:09.812: W/System.err(3625): java.io.IOException: Service not Available
03-07 12:55:09.862: W/System.err(3625): at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
03-07 12:55:09.872: W/System.err(3625): at com.kodspider.parkon.Find_Tab_MainActivity$LoadPlaces.doInBackground(Find_Tab_MainActivity.java:174)
03-07 12:55:09.872: W/System.err(3625): at com.kodspider.parkon.Find_Tab_MainActivity$LoadPlaces.doInBackground(Find_Tab_MainActivity.java:1)
03-07 12:55:09.872: W/System.err(3625): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-07 …Run Code Online (Sandbox Code Playgroud) 我收到此错误:
FATAL EXCEPTION: main
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = game.Level)
at android.os.Parcel.writeSerializable(Parcel.java)
at android.os.Parcel.writeValue(Parcel.java)
at android.os.Parcel.writeMapInternal(Parcel.java)
at android.os.Bundle.writeToParcel(Bundle.java)
at android.os.Parcel.writeBundle(Parcel.java)
at android.content.Intent.writeToParcel(Intent.java)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java)
at android.app.Instrumentation.execStartActivity(Instrumentation.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at menu.AreaAdapter$1.onClick(AreaAdapter.java:93)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.NotSerializableException: menu.AreaActivity
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368) …Run Code Online (Sandbox Code Playgroud) 我试图从SD卡读取XML文件.路径很好,但它说:
java.io.FileNotFoundException:/file:/mnt/sdcard/Reginfo/output/data.xml(没有这样的文件或目录)
以下是我尝试阅读此文件的方法:
FileInputStream file = new FileInputStream(new File("file://"
+ Environment.getExternalStorageDirectory()
+ "/RegInfo/output/data.xml"));
Run Code Online (Sandbox Code Playgroud)
我可以sdCard/RegInfo/output在文件资源管理器中的文件夹中看到此文件.
我试图打开一个使用python存在的文件,如果我在命令行中使用gedit打开它,则打开完美.
但是,我收到以下错误消息:
andreas@ubuntu:~/Desktop/Thesis/Codes/ModifiedFiles$ python vis.py -f myoutputcsv.csv
Matplotlib version 1.3.1
Traceback (most recent call last):
File "vis.py", line 1082, in <module>
reliability_table = ReliabilityTable(reliability_table_file)
File "vis.py", line 112, in __init__
self.read(filename)
File "vis.py", line 139, in read
self.data = genfromtxt(filename, delimiter=',',comments='#', dtype=float)
File "/usr/lib/python2.7/dist-packages/numpy/lib/npyio.py", line 1344, in genfromtxt
fhd = iter(np.lib._datasource.open(fname, 'rbU'))
File "/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.py", line 147, in open
return ds.open(path, mode)
File "/usr/lib/python2.7/dist-packages/numpy/lib/_datasource.py", line 496, in open
raise IOError("%s not found." % path)
IOError: ~/Desktop/Thesis/Codes/ModifiedFiles/reliability_table_2.csv not found.
Run Code Online (Sandbox Code Playgroud)
你知道我可能做错了什么吗?我对python的经验很少,我找不到文件在命令行打开但不使用python的原因.
我发现有时在IO操作中会抛出常见的IOException.我可以使用Marshal.GetHRForException(异常e)方法(在这里找到)来确定特定的错误代码.之后,我想使用我的应用程序特定的错误代码重新抛出异常,以便向用户提供一些错误的提示.但我无法找到IOException的可能HResult值列表.
我坚持的另一件事是,对于不同的HResult代码,根本原因可能是相同的 - 例如,0x8007052E和0x80070569 - 都对应于Logon failure: unknown user name or bad password.
我试图搜索类似"IOException HResult values"之类的东西,但是没有什么特别的用于映射IOException HResult与人类可读的错误(像这样或这样).
我也在这里看到了一个非常相似的问题,但仍然没有解决方案.
那么,有关IOException HResults值的文档在哪里?
class Demo
{
public static void main(String args[]) throws java.io.IOException
{
try(FileInputStream fin = new FileInputStream("Demo.txt"))
{
//This block is executed successfully
}
System.out.println("Will it be executed if error occurs in try clause");
}
}
Run Code Online (Sandbox Code Playgroud)
假设代码中的代码try block执行成功,有些代码exception发生try with resource clause,这意味着auto closing文件中发生了异常.
try with resource clause?我想问的是,该异常会被抛到JVM并且会突然终止我的程序并且该println语句不会被执行吗?
我可以捕获该异常,以便还可以执行剩余的程序吗?
我正在使用springboot应用程序。当应用程序部署在外部tomcat服务器上时,我经常遇到以下异常。但是,当我通过springboot的内部tomcat在本地测试应用程序时,它根本不会显示此错误。
org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:321)
at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:284)
at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:118)
at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.flush(OnCommittedResponseWrapper.java:513)
at com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1048)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:953)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:285)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.asn.framework.security.CustomAuthenticationTokenFilter.successfulAuthentication(CustomAuthenticationTokenFilter.java:163)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:240)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.asn.framework.core.CorsConfigurationFilter.doFilter(CorsConfigurationFilter.java:35)
at …Run Code Online (Sandbox Code Playgroud) ioexception ×10
java ×5
android ×3
.net ×1
c# ×1
geocode ×1
hresult ×1
javasound ×1
matplotlib ×1
mp3 ×1
numpy ×1
parcelable ×1
python ×1
python-2.7 ×1
serializable ×1
spring-boot ×1
swing ×1
tomcat ×1