我在设置对象之前检查以确保对象不是 Null,但它仍然返回 Null。
代码:
JSONObject json = jparse.getJSONFromUrl(URL);
JSONObject c;
JSONObject d;
try {
pictures = json.getJSONArray(TAG_PICTURES);
c = pictures.getJSONObject(2);
gallery = c.getJSONArray(TAG_GALLERY);
Log.d(tag, "after pictures");
} catch (JSONException e) {
e.printStackTrace();
}
try {
//get every instance of thumbPath here
//looping through all of Gallery
for(int z = 0; z < gallery.length(); z++){
thumbpaths = new String[gallery.length()];
captions = new String[gallery.length()];
d = gallery.getJSONObject(z);
String thumbpath = d.getString(TAG_THUMBPATHS);
String Captions = d.getString(TAG_CAPTIONS);
Log.d(tag, "Captions:" + Captions);
Log.d(tag, "Path:" + thumbpath);
if(thumbpath != null && Captions != null){
thumbpaths[z] = thumbpath;
captions[z] = Captions;
}else{
Log.d(tag, "thumbpath or Caption null");
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(thumbpaths != null){
for(int i = 0; i < thumbpaths.length; i++){
Log.d(tag,"thumbPaths:" + thumbpaths[i]);
}
bitmaps = getImagesFromPaths(thumbpaths);
}
您可以从上面看到我正在解析一个 JSON 对象并从中获取路径列表。这些路径需要传递给getImagesFromPaths(paths)
它永远不会到达并崩溃应用程序,因为它在除最后一条路径之外的所有内容上都返回 null。
我if(thumbpath != null && Captions != null)
在将它设置到数组之前检查过,我不明白为什么它仍然会放置它而不移动到我的日志中。
我怎样才能让它拥有所有路径,以便我可以发送它们以从 URL 接收?