Android : Android JSON image download throws error threadid=12: thread exiting with uncaught exception

on Monday, July 7, 2014


I am downloading images from url's provided by a JSON document. At first my app seems to be working correctly, pulling in and placing images and catching the exceptions when there is no image url in the array element but suddenly it crashes and my error log is showing something to the tune of W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0xa4b79648)


I know there is a couple of threads on stackoverflow that deal with this error and I've read most if not all but I'm having trouble understanding how to apply their solutions to my problem. It seems that I may have a concurrency problem and am reading data while its being written? I'm not super experienced when it comes to thread handling in android. Can someone point me in the correct direction and perhaps explain what this error is really saying to help others like me?


Image DwnLdr class



public Drawable loadImage (BaseAdapter adapt, ImageView view)
{
this.adapter = adapt;
String url = (String) view.getTag();
if (imageCache.containsKey(url))
{
return imageCache.get(url);
}
else {
new ImageTask().execute(url);
return DEFAULT_ICON;
}
}

private class ImageTask extends AsyncTask<String, Void, Drawable>
{
private String s_url;

@Override
protected Drawable doInBackground(String... params) {
s_url = params[0];
InputStream inStream;
try {
Log.v(debugTag, "Fetching: " + s_url);
URL url = new URL(s_url);
inStream = url.openStream();
} catch (MalformedURLException e) {
Log.v(debugTag, "Malformed: " + e.getMessage());
throw new RuntimeException(e);
} catch (IOException e)
{
Log.d(debugTag, "I/O : " + e.getMessage());
throw new RuntimeException(e);

}
return Drawable.createFromStream(inStream, "src");
}

@Override
protected void onPostExecute(Drawable result) {
super.onPostExecute(result);
synchronized (this) {
imageCache.put(s_url, result);
}
adapter.notifyDataSetChanged();
}

}


View Adapter Class



ListData data = topics.get(position);
try {
long lg = Long.valueOf(data.getPostTime())*1000;
Date date = new Date(lg);
String postTime = new SimpleDateFormat("MM dd, yyyy hh:mma").format(date);

holder.data = data;
holder.listName.setText(data.getTitle());
holder.authorName.setText(data.getAuthor());
holder.postTime.setText(postTime);
holder.redditScore.setText(data.getrScore());

Log.v(DEBUG_TAG, "Cell Created");
}catch (Exception e){
e.printStackTrace();
Log.v(DEBUG_TAG,"Cell Not Created Due to: ",e);
}

if(data.getImageUrl()!=null){
try {
holder.thumbnail.setTag(data.getImageUrl());


Drawable drawable = imgGet.loadImage(this, holder.thumbnail);
if (drawable != null) {
holder.thumbnail.setImageDrawable(drawable);
} else {
holder.thumbnail.setImageResource(R.drawable.filler_icon);
}
}catch (Exception e){
e.printStackTrace();
Log.v(DEBUG_TAG,"no image: ",e);

}

return convertView;
}


Main Class Adapter Set



public static class MyViewHolder {
public TextView listName, authorName, redditScore, postTime;
public Button goButton;
public ImageView thumbnail;
public ListData data;
}
public void setTopics(ArrayList<ListData> data) {
this.data = data;
this.postList.setAdapter(new RedditDataAdapter(this, this.getImg, this.layoutInflater,this.data));

}


Error Log



V/ImageWorker﹕ Malformed: Protocol not found:
V/ImageWorker﹕ Fetching: http://b.thumbs.redditmedia.com/6Ui_6IX22fize1ce.jpg
W/dalvikvm﹕ threadid=12: thread exiting with uncaught exception (group=0xa4b79648)
I/Process﹕ Sending signal. PID: 1976 SIG: 9

0 comments:

Post a Comment