[英]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. 您应该做两件事。
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错误处理程序中的错误通知用户,还可以添加一个按钮以重试该请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.