java.lang.IllegalArgumentException: Resource ID must not be zero.

805 views
Skip to first unread message

Akinyemi john

unread,
Mar 18, 2016, 8:33:55 AM3/18/16
to GDG Lagos
Hi

I am trying to use picasso to download images into an rss feeds placeholder, but i run the project in the emulator i got the following error message in my logcat "java.lang.IllegalArgumentException: Resource ID must not be zero." see my code below
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.mobile.gemstouch.newsdesk365.R;
import com.mobile.gemstouch.newsdesk365.WebView;
import com.mobile.gemstouch.newsdesk365.models.RSSFeed;
import com.squareup.picasso.Picasso;

import java.util.List;

public class NewsDataAdapter extends RecyclerView.Adapter<NewsDataAdapter.FeedListRowHolder> {

private List<RSSFeed> feedItemList;
private Context mContext;

public NewsDataAdapter(Context context, List<RSSFeed> feedItemList) {
this.feedItemList = feedItemList;
this.mContext = context;
}

@Override
public FeedListRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_row, null);
FeedListRowHolder mh = new FeedListRowHolder(v);
return mh;
}

@Override
public void onBindViewHolder(FeedListRowHolder feedListRowHolder, int i) {
RSSFeed feedItem = feedItemList.get(i);

//Download image using picasso library
Picasso.with(mContext).load(feedItem.getThumbImage())
.error(R.drawable.list_placeholder)
.placeholder(R.drawable.list_placeholder)
.into(feedListRowHolder.thumbImage);


feedListRowHolder.rssFeed = feedItem;
feedListRowHolder.title.setText(feedItem.getTitle());
feedListRowHolder.pubDate.setText(feedItem.getPubDate());
feedListRowHolder.thumbImage.setImageResource((feedItem.getThumbImage()));
}

@Override
public int getItemCount() {
return (null != feedItemList ? feedItemList.size() : 0);
}

public class FeedListRowHolder extends RecyclerView.ViewHolder {

protected TextView title;
protected TextView pubDate;
protected ImageView thumbImage;
protected RSSFeed rssFeed;

public FeedListRowHolder(View view) {
super(view);

this.title = (TextView) view.findViewById(R.id.tvtitle);
this.pubDate = (TextView) view.findViewById(R.id.tvpubdate);
this.thumbImage = (ImageView) view.findViewById(R.id.thumbImage);

view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


Intent webIntent = new Intent(v.getContext(), WebView.class);

webIntent.putExtra("title", rssFeed.getTitle().toString());

webIntent.putExtra("url", rssFeed.getLink().toString());

// String url=mRssFeedList.get(position).getLink().toString();

// Log.i("onlcik Recycler",url);

v.getContext().startActivity(webIntent);
}
});
}

}

}
Kindly help



Omonayajo Oladapo Adeola

unread,
Mar 18, 2016, 9:51:26 AM3/18/16
to lagos...@googlegroups.com
First off, I think it would be better to send the LogCat details too.

But I’d take a wild guess here.

This line of code:  feedListRowHolder.thumbImage.setImageResource((feedItem.getThumbImage())); isn’t required anymore since you’ve used Picasso to load the image. I’d assume that feedItem.getThumbImage() returns a String (presumably, the url for the image), but setImageResource expects an android resource (which is really an integer reference).

So, take out that line and it should work.

Like I said earlier, it’s a shot in the dark but one I feel a bit confident about.


Cheers.


OMONAYAJO OLADAPO ADEOLA
Full-Stack Software Developer
+234-806-293-5721

--
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 
[ Quicklinks ]
Join on G+: http://goo.gl/wKOuQ
Mailing List:http://bit.ly/lagosgtuggroup
Unsubscribe: http://goo.gl/0y8TB
Blog: http://gdglagos.com
Twitter Handle: http://twitter.com/@gtuglagos
 
---_---_---_---_---_---_---_---_---_---_---_---_---_---_---
---
You received this message because you are subscribed to the Google Groups "GDG Lagos" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagos-gtug+...@googlegroups.com.
To post to this group, send email to lagos...@googlegroups.com.
Visit this group at https://groups.google.com/group/lagos-gtug.
For more options, visit https://groups.google.com/d/optout.

Akinyemi john

unread,
Mar 18, 2016, 10:50:49 AM3/18/16
to GDG Lagos
ADEOLA thank you for your reply when i tried it the error still persist since you ask for the whole logcat see it below

03-18 10:41:40.655    5664-5664/com.mobile.gemstouch.newsdesk365 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3a58ba8)
03-18 10:41:40.905    5664-5664/com.mobile.gemstouch.newsdesk365 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mobile.gemstouch.newsdesk365, PID: 5664

    java.lang.IllegalArgumentException: Resource ID must not be zero.
            at com.squareup.picasso.Picasso.load(Picasso.java:237)
            at com.mobile.gemstouch.newsdesk365.adapters.NewsDataAdapter.onBindViewHolder(NewsDataAdapter.java:45)
            at com.mobile.gemstouch.newsdesk365.adapters.NewsDataAdapter.onBindViewHolder(NewsDataAdapter.java:23)
            at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5084)
            at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4385)
            at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4278)
            at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1947)
            at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1359)
            at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1322)
            at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
            at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2673)
            at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2971)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1626)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
            at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
            at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
            at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
            at android.view.View.layout(View.java:14817)
            at android.view.ViewGroup.layout(ViewGroup.java:4631)
            at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
            at android.view.ViewRootImpl$TraversalRunnab

Omonayajo Oladapo Adeola

unread,
Mar 18, 2016, 11:17:18 AM3/18/16
to lagos...@googlegroups.com
What data type does feedItem.getThumbImage()return?



OMONAYAJO OLADAPO ADEOLA
Full-Stack Software Developer
+234-806-293-5721

Reply all
Reply to author
Forward
0 new messages