无法从reddit json结果中解析图像URL

时间:2018-02-12 13:18:50

标签: android json nullpointerexception gson retrofit2

检查this for JSON DATA

我想解析preview -> images ->source -> url

public class LChildData {

    @SerializedName("title")
    @Expose
    public String title;

    @SerializedName("preview")
    @Expose
    public LPreview preview;

}

public class LPreview {

    @SerializedName("images")
    @Expose
    public List<LImages> images =null;
}

public class LImages {

    @SerializedName("source")
    @Expose
    public LSource source;
}

public class LSource {

    @SerializedName("url")
    @Expose
    public String url;

}

ViewHolder代码

 if (isValidImageUrl(holder.mItem.data.preview.images.get(0).source.url)) {
        Picasso.with(mContext)
                .load(holder.mItem.data.preview.images.get(0).source.url)
                .into(holder.mPostThumbnail);
    }

错误

  

D / ViewAdapter:onBindViewHolder:image_url    :https://i.redditmedia.com/RoARvRoBJHQihiWK_aHdhEZG2kabxNvmvY5kZKFkskk.jpg?s=037d08a057a7a6d253ab0937b6247353
  java.lang.NullPointerException:尝试调用虚方法    &#39; java.util.List com.example.dex.redditclient.listings.model.LPreview.getImages()&#39;在com.example.dex.redditclient.listings.ViewAdapter.onBindViewHolder(ViewAdapter.java:60)的null对象引用上

0 个答案:

没有答案