I'm uing a custom base adapter to get title, link, description,pubdate, guid from rss feeds. i first implemented the application directly using simple array adapter and it worked fine. but on implementing it with custom base adapter i am having app stopped working error.
this is my bean class RssItem.java
package com.maulik.rss;
public class RssItem {
String _title;
String _link;
String _description;
String _pubdate;
String _guid;
// constructor
public RssItem(){
}
// constructor with parameters
public RssItem(String title, String link, String description, String pubdate, String guid){
this._title = title;
this._link = link;
this._description = description;
this._pubdate = pubdate;
this._guid = guid;
}
public void setTitle(String title){
this._title = title;
}
public void setLink(String link){
this._link = link;
}
public void setDescription(String description){
this._description = description;
}
public void setPubdate(String pubDate){
this._pubdate = pubDate;
}
public void setGuid(String guid){
this._guid = guid;
}
/**
* All GET methods
* */
public String getTitle(){
return this._title;
}
public String getLink(){
return this._link;
}
public String getDescription(){
return this._description;
}
public String getPubdate(){
return this._pubdate;
}
public String getGuid(){
return this._guid;
}
}
this is my custom base adapter class RssCustomListRssItemsAdapter
public class RssCustomListRssItemsAdapter extends BaseAdapter{
Context context;
List<RssItem> rssItems;
public RssCustomListRssItemsAdapter(Context context,List<RssItem>rssItems){
this.context=context;
this.rssItems=rssItems;
}
private class ViewHolder{
TextView url,title,date,description;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return rssItems.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return rssItems.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return rssItems.indexOf(rssItems.get(position));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
ViewHolder holder=null;
if(convertView==null){
convertView=inflater.inflate(R.layout.rss_item_list_row, null);
holder.url=(TextView) convertView.findViewById(R.id.page_url);
holder.title=(TextView) convertView.findViewById(R.id.title);
holder.date=(TextView) convertView.findViewById(R.id.pub_date);
holder.description=(TextView) convertView.findViewById(R.id.link);
convertView.setTag(holder);
}else{
holder=(ViewHolder) convertView.getTag();
}
RssItem item=rssItems.get(position);
holder.url.setText(item.getLink());
holder.title.setText(item.getTitle());
holder.date.setText(item.getPubdate());
holder.description.setText(item.getDescription());
return convertView;
}
}
this is the activity called as RSS_ListRSSItemsActivity
public class RSS_ListRSSItemsActivity extends ActionBarActivity implements
OnItemClickListener {
ActionBar ab;
private ProgressDialog pDialog;
RssCustomListRssItemsAdapter adapter;
List<RssItem> rssItem = new ArrayList<RssItem>();
RssParser rssParser = new RssParser();
RssFeed rssFeed;
ListView lv;
String title, description, link, pubdate, guid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rss_item_list);
ab = getSupportActionBar();
Intent i = getIntent();
Integer site_id = Integer.parseInt(i.getStringExtra("id"));
String actionBar_title = i.getStringExtra(title);
ab.setTitle(actionBar_title);
// Getting Single website from SQLite
RssDatabaseHandler rssDB = new RssDatabaseHandler(
getApplicationContext());
RssWebSite site = rssDB.getSite(site_id);
String rss_link = site.getRSSLink();
new loadRSSFeedItems().execute(rss_link);
// selecting single ListView item
lv = (ListView) findViewById(R.id.list);
lv.setOnItemClickListener(this);
}
/**
* Background Async Task to get RSS Feed Items data from URL
* */
class loadRSSFeedItems extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
/**
* getting all recent articles and showing them in listview
* */
@Override
protected String doInBackground(String... args) {
// rss link url
String rss_url = args[0];
// list of rss items
rssItem = rssParser.getRSSFeedItems(rss_url);
// looping through each item
for (RssItem item : rssItem) {
item.getTitle();
item.getLink();
item.getDescription();
item.getPubdate();
item.getGuid();
rssItem.add(item);
}
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
adapter = new RssCustomListRssItemsAdapter(RSS_ListRSSItemsActivity.this, rssItem);
lv.setAdapter(adapter);
}
});
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String args) {
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Intent in = new Intent(getApplicationContext(),
RSS_DetailedRSSActivity.class);
// getting page url
String page_url = ((TextView) view.findViewById(R.id.page_url))
.getText().toString();
String title = ((TextView) view.findViewById(R.id.title)).getText()
.toString();
String date = ((TextView) view.findViewById(R.id.pub_date)).getText()
.toString();
String description = ((TextView) view.findViewById(R.id.link))
.getText().toString();
in.putExtra("page_url", page_url);
in.putExtra("title_url", title);
in.putExtra("date_url", date);
in.putExtra("description_url", description);
startActivity(in);
}
}
this is my logcat
I/Choreographer(18848): Skipped 137 frames! The application may be doing too much work on its main thread. W/dalvikvm(18848): threadid=12: thread exiting with uncaught exception (group=0x40b89378) FATAL EXCEPTION: AsyncTask #2 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:299) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) at java.util.concurrent.FutureTask.setException(FutureTask.java:124) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) at java.util.concurrent.FutureTask.run(FutureTask.java:137) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:856) Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569) at com.maulik.rss.RSS_ListRSSItemsActivity$loadRSSFeedItems.doInBackground(RSS_ListRSSItemsActivity.java:88) at com.maulik.rss.RSS_ListRSSItemsActivity$loadRSSFeedItems.doInBackground(RSS_ListRSSItemsActivity.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) ... 5 more
line 88 is for (RssItem item : rssItem) { also in pre execute i used progress dialog and i got leaked window error. i did spend my entire day figuring out this and using various answers on the web. please do help