【发布时间】:2015-11-20 00:54:47
【问题描述】:
我有一个在启动时执行的活动的异步任务。如果用户手动选择一个位置,该 url 包含一个作为参数传递给 asynctask 的值,并且如果用户没有指定位置,则 async 任务使用默认 url。我的问题是,如果未指定参数,我无法在代码上调用 url[0]。有没有办法检查参数是否传递到异步任务中?下面是我的尝试。我试过url[0].isEmpty() 和url[0] == null 但都给我IndexOutOfBounds 错误。
private class CallDestination extends AsyncTask<String, Void, JSONObject>{
protected JSONObject doInBackground(String...url){
String MYURL = "";
if(url[0].isEmpty()){
MYURL = "http://thevisitapp.com/api/destinations/read?identifiers=10011";
} else{
MYURL = "http://thevisitapp.com/api/destinations/read?identifiers=" + url[0];
}
//TODO make this dynamic as it's passed in from other activity through intent
HttpRequest request = new HttpRequest();
return request.getJSONFromUrl(MYURL);
}
【问题讨论】:
标签: android android-asynctask indexoutofboundsexception