简体   繁体   English

为什么在使用URLLoader时突然出现流错误?

[英]Why am I suddenly getting stream error while using URLLoader?

I've been working on an android app project for an year and I implemented this feature in the very beginning. 我从事Android应用程序项目已经一年了,一开始就实现了此功能。 The app is a expense/savings management app, and it has a feature that converts the currencies in the background if user is currently in a different country. 该应用程序是费用/储蓄管理应用程序,它具有一项功能,如果用户当前在其他国家/地区,则可以在后台转换货币。 I am using geonames API to find out the name of the country. 我正在使用地理名称API来查找国家/地区名称。 Here is the relevant code: 以下是相关代码:

countryURLRequest = new URLRequest('http://api.geonames.org/findNearby?lat='+latitudes+'&lng='+longitudes+'&username=fatninja');
countryURLLoader = new URLLoader();

countryURLLoader.load(countryURLRequest);

Today, when I sent lat and lng values from the simulator I got the said stream error at this line: 今天,当我从模拟器发送lat和lng值时,在这一行出现了上述流错误:

countryURLLoader = new URLLoader();

What's weird is that this feature has been working fine since the beginning. 奇怪的是,此功能自一开始就运行良好。 I thought it might have been a bug in the code so I ran the project from backup (from 3 months ago), it's giving the same error. 我认为这可能是代码中的错误,所以我从备份中运行了项目(从3个月前开始),它给出了相同的错误。 I know for a fact that it was working 3 months ago. 我知道一个事实,那就是三个月前。 What could be the problem? 可能是什么问题呢?

This error is indicating that you're running into a problem while fetching the data. 此错误表明您在获取数据时遇到问题。 Nothing's wrong with your code. 您的代码没有错。 It might be that your network configuration has changed, and that's preventing access to the web service. 可能是您的网络配置已更改,这阻止了对Web服务的访问。

This is further supported by the fact that you're facing the same problem with your previously working code. 事实是,您以前使用的代码也面临着同样的问题,这进一步证明了这一点。

There are two things you should do. 您应该做两件事。

  1. Add an IO error event handler and a HTTP status event handler. 添加IO错误事件处理程序和HTTP状态事件处理程序。

    var loader:URLLoader = new URLLoader; var loader:URLLoader =新的URLLoader; loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_ioErrorHandler); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loader_ioErrorHandler); // Note that the listener is added to the contentLoaderInfo object loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, loader_httpStatusHandler); //注意,已将侦听器添加到contentLoaderInfo对象loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,loader_httpStatusHandler); loader.load(new URLRequest("www.example.com")); loader.load(new URLRequest(“ www.example.com”));

    function loader_ioErrorHandler(e:IOErrorEvent):void { // Handle the error trace(e.text); 函数loader_ioErrorHandler(e:IOErrorEvent):void {//处理错误跟踪(e.text); } }

    function loader_httpStatusHandler(e:HTTPStatusEvent.HTTP_STATUS):void { trace(e.status); 函数loader_httpStatusHandler(e:HTTPStatusEvent.HTTP_STATUS):void {trace(e.status); } }

Add labels to notify the user about the error in the IO error handler, and maybe a button to retry the request. 添加标签以将IO错误处理程序中的错误通知用户,还可以添加一个按钮以重试该请求。

  1. Increase the duration of the timeout by using the requestTimeout property of the HTTPService instance. 通过使用HTTPService实例的requestTimeout属性来增加超时的持续时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在使用 android studio 时会出现此错误。? - Why am I getting this error while using android studio.? 如果我运行应用程序,我突然收到此错误,这是什么问题? - If I run application , I am suddenly getting this error , what is the problem? 为什么使用okhttp3登录instagram时出现403错误? - Why am I getting 403 error while logging in to instagram using okhttp3? 为什么在使用realm.executeTransactionAsync()方法时出现编译时错误? - Why I am getting compile time error while using realm.executeTransactionAsync() method? 为什么运行Google Maps活动时出现此错误? - Why i am getting this error while running google maps activity? 将 retfofit 与 MVVM 一起使用时出现错误 - I am getting error while using retfofit with MVVM 为什么我在使用音频播放器时出错:^0.17.3 package,错误是“任务':app:processDebugManifest'执行失败,构建失败” - why i am getting error while using audioplayers: ^0.17.3 package, error is “Execution failed for task ':app:processDebugManifest', Build failed” 为什么使用 Jetpack Compose TextField 时出现错误? - Why am I getting an error using Jetpack Compose TextField? 启动应用程序时出现此错误 - I am getting this error while launching the app 为什么我会收到数据库错误的错误:检索数据时权限被拒绝 - why am i getting this error of Database Error: Permission Denied while retrieving data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM