使用Jsoup图像URL不获取连接到NetworkImageVi

使用Jsoup图像URL不获取连接到NetworkImageVi

本文介绍了使用Jsoup图像URL不获取连接到NetworkImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSON请求,我收到图片的URL对特定文章,但 NetWorkImageView 未获得该图片的URL。下面是我的要求:

In Json request, I am getting Image URL for particular article but NetWorkImageView is not getting that Image URL.Here is my request:

JsonObjectRequest objectRequest = new JsonObjectRequest(url,null,new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {

                hidePDialog();
                JSONObject rss = response.getJSONObject("rss");
                JSONObject channel = rss.getJSONObject("channel");
                JSONArray item = channel.getJSONArray("item");
                Log.d(TAG, item.toString());
                for (int i = 0; i < item.length(); i++) {


                    JSONObject obj = item.getJSONObject(i);
                    Movie movie = new Movie();
                    movie.setTitle(obj.getString("title"));
                    //Image Url
                    String imageLink = obj.getString("description");
                    Document doc = Jsoup.parse(imageLink);
                    Element link = doc.select("img").first();
                    //System.out.println(link.absUrl("src"));

                    //ERROR comes with line below.
                    movie.setThumbnailUrl(link.absUrl("src"));
                    movieList.add(movie);

                }



            } catch (JSONException e) {
                e.printStackTrace();
            }
            adapter.notifyDataSetChanged();
        }

    },new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            VolleyLog.d(TAG, "Error: " + volleyError.getMessage());
            hidePDialog();
        }
    });
 AppController.getInstance().addToRequestQueue(objectRequest);
    return rootView;
}

看起来完成,但我仍然在这里做愚蠢的错误。获取傻 NullPointerException异常。我尝试了一段时间,但现在困在这里一段时间了。误差小,但无法找到它,虽然。

It looks complete but I am still making silly mistake here. Getting silly NullPointerException. I trying it for some time now but stuck here for while now. Error is small but unable to find it though.

如果你需要更多的code片断,然后让我知道。您的帮助将是非常美联社preciated。对不起,愚蠢的问题。

If you need more code snippets then let me know.Your help will be very much appreciated. Sorry for dumb question.

修改1 logcat的

EDIT 1Logcat

推荐答案

               Element link = doc.select("img").first();
               movie.setThumbnailUrl(link.absUrl("src"));

我应该用:

                    Elements link = doc.select("img");
                    if(link.attr("src")!= null)
                    {
                        movie.setThumbnailUrl(link.attr("src"));
                    }
                    else {
                        movie.setThumbnailUrl(null);
                    }

链接是不为空。我的做法是错误的。

Link was not null. My approach was wrong.

这篇关于使用Jsoup图像URL不获取连接到NetworkImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:21