Android 在移动互联网上,但在WiFi上工作时,出现边界错误
我正在制作一个RSS阅读器应用程序,从xml文件中获取坐标,然后在地图上绘制坐标。我将此任务称为异步任务,但给出了: 慢速internet连接上的java.lang.ArrayIndexOutOfBoundsException。另外,我正在一个不同的片段中并排运行另一个异步 下面是此异步的代码:Android 在移动互联网上,但在WiFi上工作时,出现边界错误,android,google-maps,android-asynctask,indexoutofboundsexception,Android,Google Maps,Android Asynctask,Indexoutofboundsexception,我正在制作一个RSS阅读器应用程序,从xml文件中获取坐标,然后在地图上绘制坐标。我将此任务称为异步任务,但给出了: 慢速internet连接上的java.lang.ArrayIndexOutOfBoundsException。另外,我正在一个不同的片段中并排运行另一个异步 下面是此异步的代码: void getDataInAsyncTask(){ final ProgressDialog pd = new ProgressDialog(getActivity(), ProgressDi
void getDataInAsyncTask(){
final ProgressDialog pd = new ProgressDialog(getActivity(), ProgressDialog.STYLE_SPINNER);
pd.setTitle("Loading ...");
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.setMessage("Please wait while we load nearby restaurants");
AsyncTask<Void, Void, List<Data>> task = new AsyncTask<Void, Void, List<Data>>() {
@Override
protected void onPreExecute() {
pd.show();
}
protected List<Data> doInBackground(Void... urls) {
// Debug the task thread name
Log.d("ITCRssReader", "inside");
try {
// Create RSS reader
RssReader rssReader = new RssReader("http://findaway.in/card/restaurants/feed.xml");
Log.d("ITCRssReader", "inside1");
// Parse RSS, get items
// Log.d("ITCRssReader", rssReader.getItems().get(3).getName());
return rssReader.getItems();
} catch (Exception e) {
Toast.makeText(getActivity(), "Slow or No Internet Connection",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
return null;
}
protected void onPostExecute(List<Data> result) {
Log.d("Map", result.get(3).getName());// <-chal raha hai yaha tk
MapList = new ArrayList<Data>(result);
// Get a ListView from main view
int i=0;
for(i=0 ; i<MapList.size();i++)
{
Log.d("map latlong",MapList.get(i).getLatLong());
String loc = MapList.get(i).getLatLong();
String s[] = loc.split(",");
LatLng mylocation=new LatLng(Double.parseDouble(s[0]),Double.parseDouble(s[1]));
//Log.d("Location","Double.parseDouble(s[0]),Double.parseDouble(s[1])");
Marker m = map.addMarker(new MarkerOptions().position(mylocation)
.title(MapList.get(i).getName()));
//m.showInfoWindow();
}
pd.dismiss();
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
void getDataInAsyncTask(){
final ProgressDialog pd=新建ProgressDialog(getActivity(),ProgressDialog.STYLE_微调器);
pd.设置标题(“加载…”);
pd.可设置可取消(假);
pd.SetUndeterminate(真);
pd.setMessage(“请稍候,我们正在加载附近的餐厅”);
AsyncTask任务=新建AsyncTask(){
@凌驾
受保护的void onPreExecute(){
pd.show();
}
受保护列表doInBackground(无效…URL){
//调试任务线程名称
日志d(“ITCRssReader”,“内部”);
试一试{
//创建RSS阅读器
RssReader RssReader=新RssReader(“http://findaway.in/card/restaurants/feed.xml");
日志d(“ITCRssReader”,“内部1”);
//解析RSS,获取项目
//Log.d(“ITCRssReader”,rssReader.getItems().get(3.getName());
返回rssReader.getItems();
}捕获(例外e){
Toast.makeText(getActivity(),“慢速或无Internet连接”,
Toast.LENGTH_LONG).show();
意向意向=新意向(意向.行动\主要);
intent.addCategory(intent.CATEGORY_HOME);
intent.setFlags(intent.FLAG\u活动\u新任务);
星触觉(意向);
}
返回null;
}
受保护的void onPostExecute(列表结果){
Log.d(“Map”,result.get(3.getName());//String s[]=loc.split(,”);
没有拆分任何内容,即,loc
字符串中没有逗号-您需要找出原因。未完成的结果
被接收,因此loc
只有28
。我在刚刚检查的结果数组中接收到85个对象,这些对象提交的都是正确的,当internet运行时,日志会打印所有85个坐标d高,但当它低时失败。由于数据提取速度慢,在这两者之间发生了一些错误。我想我能做什么?如何处理这个问题?刷新片段/尝试捕获?可能会有所帮助。