我正在使用Rerofit库获取媒体形式instagram Instagram media api
并将图片网址加载到arraylist中
public void loadImageUrls() {
Call<InstagramResponse> getdata = CustomApplication.getRestClient().getService().getInstagramResponse();
getdata.enqueue(new Callback<InstagramResponse>() {
@Override
public void onResponse(Response<InstagramResponse> response, Retrofit retrofit) {
if (response.body().getStatus().equals("ok")) {
int x = response.body().getItems().size();
for (int i = 0; i < x; i++) {
IMAGE_URLS.add(response.body().getItems().get(i).getImages().getThumbnail().getUrl());
IMAGE_STANDARD_URLS.add(response.body().getItems().get(i).getImages().getThumbnail().getUrl());
//Toast.makeText(mContext, "Image " + i + " Loaded", Toast.LENGTH_LONG).show();
}
grid.setAdapter(new ImageAdapter(mContext, IMAGE_URLS));
} else {
Toast.makeText(mContext, "No Response in API", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Throwable t) {
Log.i("eeeeeeeee:", t.toString());
Toast.makeText(mContext, "Please Check Your Network Connections", Toast.LENGTH_LONG).show();
}
});
}
但它给出了错误确定IMAGE_STANDARD_URLS.add(获取标准网址时) 但适用于IMAGE_URLS.add(缩略图网址)
json的回应是
{
"status": "ok",
"items": [{
"can_delete_comments": false,
"code": "4eb_I4L0pu",
"location": null,
"images": {
"low_resolution": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/s320x320\/e15\/11357325_874501389301299_1267420428_n.jpg?ig_cache_key=MTAxNzM3MzY1MTk0NzcwMjg5NA%3D%3D.2",
"width": 320,
"height": 320
},
"thumbnail": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/s150x150\/e15\/11357325_874501389301299_1267420428_n.jpg?ig_cache_key=MTAxNzM3MzY1MTk0NzcwMjg5NA%3D%3D.2",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/e15\/11357325_874501389301299_1267420428_n.jpg?ig_cache_key=MTAxNzM3MzY1MTk0NzcwMjg5NA%3D%3D.2",
"width": 640,
"height": 640
}
},
"can_view_comments": true,
"comments": {
"count": 1429,
"data": [{
"created_time": "1458228411",
"text": "vorrei essere quel cane",
"from": {
"username": "sassa_babba",
"profile_picture": "https:\/\/igcdn-photos-f-a.akamaihd.net\/hphotos-ak-xpt1\/t51.2885-19\/s150x150\/12383491_1775370549352709_39430552_a.jpg",
"id": "2022426329",
"full_name": "OBB:595\ud83d\udd10\u2764\ufe0f Ricambio.like\ud83d\ude4c\ud83c\udffb"
},
"id": "1208029933892225506"
}, {
"created_time": "1458228413",
"text": "@_giorgiaaquadrii_",
"from": {
"username": "sassa_babba",
"profile_picture": "https:\/\/igcdn-photos-f-a.akamaihd.net\/hphotos-ak-xpt1\/t51.2885-19\/s150x150\/12383491_1775370549352709_39430552_a.jpg",
"id": "2022426329",
"full_name": "OBB:595\ud83d\udd10\u2764\ufe0f Ricambio.like\ud83d\ude4c\ud83c\udffb"
},
"id": "1208029944847747556"
}, {
"created_time": "1458230059",
"text": "\ud83d\ude02\ud83d\ude02\ud83d\ude02\u2764 @sassa_babba a chi lo dici",
"from": {
"username": "_giorgiaaquadrii_",
"profile_picture": "https:\/\/igcdn-photos-d-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/s150x150\/12725166_498932666944947_495489302_a.jpg",
"id": "2670800058",
"full_name": "G\u00ef\u00f8rg\u012b\u00e6\ud83d\udc96"
},
"id": "1208043757965888019"
}, {
"created_time": "1458275284",
"text": "The sighted of the dog sea the Jupiter's sight the rippers the oceans clouds cry for rain but omen won't aloud that bee cross the no where without compass#",
"from": {
"username": "kamrolzaman",
"profile_picture": "https:\/\/igcdn-photos-f-a.akamaihd.net\/hphotos-ak-xtp1\/t51.2885-19\/10311088_284020995108189_2128683611_a.jpg",
"id": "1332536123",
"full_name": "Kamrolzaman Yusoof"
},
"id": "1208423132754299242"
}]
},
"alt_media_url": null,
"caption": {
"created_time": "1435500411",
"text": "Seriously, its been forever!!! I'm so sorry I've been gone!",
"from": {
"username": "tomcruiseofficial_",
"profile_picture": "https:\/\/igcdn-photos-e-a.akamaihd.net\/hphotos-ak-xta1\/t51.2885-19\/11881704_1486545434995812_1292550057_a.jpg",
"id": "195828025",
"full_name": "Tom Cruise"
},
"id": "1017376582180751688"
},
"link": "https:\/\/www.instagram.com\/p\/4eb_I4L0pu\/",
"likes": {
"count": 21469,
"data": [{
"username": "fariborz_shams",
"profile_picture": "https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xat1\/t51.2885-19\/s150x150\/12135375_656758564467358_757413338_a.jpg",
"id": "1377562413",
"full_name": "Fariborz Sh"
}, {
"username": "simar_kaur31",
"profile_picture": "https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xat1\/t51.2885-19\/s150x150\/12519204_1725998514285846_687501394_a.jpg",
"id": "2304168545",
"full_name": "Simarpreet \ud83d\udc9e"
}, {
"username": "sinakurschat",
"profile_picture": "https:\/\/igcdn-photos-b-a.akamaihd.net\/hphotos-ak-xfp1\/t51.2885-19\/s150x150\/12628031_1681686505423561_369144536_a.jpg",
"id": "1682097174",
"full_name": "sinakurschat"
}, {
"username": "kale_diksha",
"profile_picture": "https:\/\/igcdn-photos-b-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/s150x150\/12797808_1709699612632081_405037044_a.jpg",
"id": "2128472803",
"full_name": "\ud83c\udf1fDiksha kale\ud83c\udf1f"
}]
},
"created_time": "1435500411",
"user_has_liked": false,
"type": "image",
"id": "1017373651947702894_195828025",
"user": {
"username": "tomcruiseofficial_",
"profile_picture": "https:\/\/igcdn-photos-e-a.akamaihd.net\/hphotos-ak-xta1\/t51.2885-19\/11881704_1486545434995812_1292550057_a.jpg",
"id": "195828025",
"full_name": "Tom Cruise"
}
}, {
"can_delete_comments": false,
"code": "z1ZddUr0qs",
"location": null,
"images": {
"low_resolution": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/s320x320\/e15\/11008319_335099836698595_490927836_n.jpg?ig_cache_key=OTMzNzY0NDczMjYyMzk0MDI4.2",
"width": 320,
"height": 320
},
"thumbnail": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/s150x150\/e15\/11008319_335099836698595_490927836_n.jpg?ig_cache_key=OTMzNzY0NDczMjYyMzk0MDI4.2",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "https:\/\/scontent-sin1-1.cdninstagram.com\/t51.2885-15\/e15\/11008319_335099836698595_490927836_n.jpg?ig_cache_key=OTMzNzY0NDczMjYyMzk0MDI4.2",
"width": 640,
"height": 640
}
},
"can_view_comments": true,
"comments": {
"count": 1005,
"data": [{
"created_time": "1458092427",
"text": "@nmedina99 your husband!!!\ud83d\ude15",
"from": {
"username": "sarah.medina01",
"profile_picture": "https:\/\/igcdn-photos-c-a.akamaihd.net\/hphotos-ak-xtp1\/t51.2885-19\/s150x150\/12328251_1706592859620818_1377092563_a.jpg",
"id": "2979787255",
"full_name": "Sarah Medina"
},
"id": "1206889214074898930"
}, {
"created_time": "1458161986",
"text": "@nadaodeh98 \ud83d\ude2d\ud83d\ude2d\ud83d\ude2d\ud83d\ude2d",
"from": {
"username": "sobhyehmosa",
"profile_picture": "https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/s150x150\/12783832_1512530792387446_1127138415_a.jpg",
"id": "2989640398",
"full_name": "Sob7yeh\ud83c\udf38"
},
"id": "1207472714532473810"
}, {
"created_time": "1458162022",
"text": "@sobhyehmosa \u0632\u064a \u0627\u0644\u064a \u0639\u0646\u0627 \ud83d\ude02",
"from": {
"username": "nadaodeh98",
"profile_picture": "https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/s150x150\/12818921_591515934340470_1491802960_a.jpg",
"id": "1120968288",
"full_name": "Nada Odeh | \u0646\u062f\u0649\ud83c\udf93"
},
"id": "1207473020053965803"
}, {
"created_time": "1458162053",
"text": "@nadaodeh98 \u0627\u0627\u0627\u0627\u0627\u0627\u0627\u0627\u0627\u0627 \u0646\u0633\u062e\u0647 \ud83d\ude02",
"from": {
"username": "sobhyehmosa",
"profile_picture": "https:\/\/igcdn-photos-g-a.akamaihd.net\/hphotos-ak-xaf1\/t51.2885-19\/s150x150\/12783832_1512530792387446_1127138415_a.jpg",
"id": "2989640398",
"full_name": "Sob7yeh\ud83c\udf38"
},
"id": "1207473283154266122"
}]
"more_available": true
}
logcat错误是
03-18 11:47:43.745 31691-31691/com.deepak.picassogrid E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.deepak.picassogrid.MainActivity$1.onResponse(MainActivity.java:64)
at retrofit.ExecutorCallAdapterFactory$ExecutorCallback$1.run(ExecutorCallAdapterFactory.java:86)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
03-18 11:47:45.206 31691-31691 / com.deepak.picassogrid I / Process:发送信号。 PID:31691 SIG:9
和InstagramResponse是
public class InstagramResponse {
private String status;
private List<Item> items = new ArrayList<Item>();
private Boolean moreAvailable;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
* @return The status
*/
public String getStatus() {
return status;
}
/**
* @param status The status
*/
public void setStatus(String status) {
this.status = status;
}
/**
* @return The items
*/
public List<Item> getItems() {
return items;
}
/**
* @param items The items
*/
public void setItems(List<Item> items) {
this.items = items;
}
/**
* @return The moreAvailable
*/
public Boolean getMoreAvailable() {
return moreAvailable;
}
/**
* @param moreAvailable The more_available
*/
public void setMoreAvailable(Boolean moreAvailable) {
this.moreAvailable = moreAvailable;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
和Thumbnail.java是
public class Thumbnail {
private String url;
private Integer width;
private Integer height;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
/**
* @return The width
*/
public Integer getWidth() {
return width;
}
/**
* @param width The width
*/
public void setWidth(Integer width) {
this.width = width;
}
/**
* @return The height
*/
public Integer getHeight() {
return height;
}
/**
* @param height The height
*/
public void setHeight(Integer height) {
this.height = height;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
和StandardResolution.java是
public class StandardResolution {
private String url;
private Integer width;
private Integer height;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
* @return The url
*/
public String getUrl() {
return url;
}
/**
* @param url The url
*/
public void setUrl(String url) {
this.url = url;
}
/**
* @return The width
*/
public Integer getWidth() {
return width;
}
/**
* @param width The width
*/
public void setWidth(Integer width) {
this.width = width;
}
/**
* @return The height
*/
public Integer getHeight() {
return height;
}
/**
* @param height The height
*/
public void setHeight(Integer height) {
this.height = height;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}