ParseFile.getUrl()'在空对象引用

时间:2016-03-22 13:08:05

标签: android parse-platform

我从解析云调用图像并使用毕加索将它们加载到我的gridview持有者中。

这是doInbackGround

@Override
       protected Void doInBackground(Void... Params) {
           feedsarraylist = new ArrayList<ParseFeeds>();
           try {
               ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("AroundMe");
               query.orderByDescending("createdAt");
               //query.whereWithinKilometers()
               ob = query.find();

               for (ParseObject feeds : ob) {
                   ParseFile thumb = (ParseFile) feeds.get("videoThumbs");
                   //ParseFile video = (ParseFile) feeds.get("file");
                   ParseFeeds map = new ParseFeeds();
                   //map.setImage(thumb.getUrl());
                  //Uri videoUri = Uri.parse(video.getUrl());
                   map.setImage(thumb.getUrl());
                   feedsarraylist.add(map);
               }

           } catch (ParseException e) {
               Log.e("ParseException", "parse: " + e);
           }
           return null;
       }

ParseFeeds.class

   public String getImage() {
        return videoThumbs;
    }

    public void setImage(String videoThumbs) {
        this.videoThumbs = videoThumbs;
    }

我把它加载到GridViewAdapter.class

  Picasso.with(context).load(feedsarraylist.get(position).getImage()).into(holder.ThumbView);

Logcat详细信息

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.parse.ParseFile.getUrl()' on a null object reference
                                                                              at com.teamtreehouse.ribbit.FeedsFragment$RemoteDataTask.doInBackground(FeedsFragment.java:67)
                                                                              at com.teamtreehouse.ribbit.FeedsFragment$RemoteDataTask.doInBackground(FeedsFragment.java:45)

1 个答案:

答案 0 :(得分:0)

我只是在这里猜测,因为你没有指明错误发生的位置。

ParseFile thumb = (ParseFile) feeds.get("videoThumbs");
map.setImage(thumb.getUrl())

如果feeds没有videoThumbs元素,则thumb将为null因此您的错误。检查feeds元素的内容。