I have downloaded one ImageDownloader code from gitHub(from Here) Now when I am trying to download the image from my webservice I am getting this Runtime Exception "ImageLoader must be init with configuration before using".
I am not able to figure it out.
And this my adapter:
public class CustomAdapter extends BaseAdapter
{
private Context context;
private ArrayList<String> logo_URL;
private ListContent listContent;
private ArrayList< TeamDataClass> teamdata = null;
private ArrayList<EventDataClass> eventdata = null;
private DisplayImageOptions options;
private ImageLoader imageLoader;
public CustomAdapter(Context context,ArrayList<String> logo_URL,ArrayList<TeamDataClass> teamdata, ArrayList<EventDataClass> eventdata)
{
this.context = context;
this.logo_URL = logo_URL;
this.teamdata = teamdata;
this.eventdata = eventdata;
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.image_for_empty_url)
.cacheOnDisc()
.imageScaleType(ImageScaleType.EXACT)
.build();
imageLoader= ImageLoader.getInstance();
}
//@Override
public int getCount()
{
return teamdata.size()/2;
}
//@Override
public Object getItem(int arg0)
{
return arg0;
}
//@Override
public long getItemId(int arg0)
{
return arg0;
}
//@Override
public View getView(int arg0, View convertview, ViewGroup arg2)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
if (convertview == null )
{
convertview = inflater.inflate(R.layout.custom_list_score, null);
listContent = new ListContent();
listContent.team_logo2 = (ImageView) convertview.findViewById(R.id.team_logo2);
listContent.team_logo1 = (ImageView) convertview.findViewById(R.id.team_logo1);
listContent.progress_team1=(ProgressBar)convertview.findViewById(R.id.progress_team_logo1);
listContent.progress_team2=(ProgressBar)convertview.findViewById(R.id.progress_team_logo2);
convertview.setTag(listContent);
}
else
{
listContent = (ListContent) convertview.getTag();
}
listContent.status.setText(eventdata.get(arg0).status);
int pos=arg0*2;
imageLoader.displayImage(logo_URL.get(pos),listContent.team_logo1, options,new ImageLoadingListener()
{
//@Override
public void onLoadingStarted()
{
listContent.progress_team1.setVisibility(View.VISIBLE);
}
//@Override
public void onLoadingFailed(FailReason failReason)
{
String message = null;
switch (failReason)
{
case IO_ERROR:
message = "Input/Output error";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
listContent.progress_team1.setVisibility(View.GONE);
listContent.team_logo1.setImageResource(android.R.drawable.ic_delete);
}
//@Override
public void onLoadingComplete(Bitmap loadedImage)
{
listContent.progress_team1.setVisibility(View.GONE);
Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
listContent.team_logo1.setAnimation(anim);
anim.start();
}
//@Override
public void onLoadingCancelled()
{
// Do nothing
}
public void onLoadingComplete() {
}
});
imageLoader.displayImage(logo_URL.get(pos+1),listContent.team_logo2, options,new ImageLoadingListener()
{
//@Override
public void onLoadingStarted()
{
listContent.progress_team2.setVisibility(View.VISIBLE);
}
//@Override
public void onLoadingFailed(FailReason failReason)
{
String message = null;
switch (failReason)
{
case IO_ERROR:
message = "Input/Output error";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
listContent.progress_team2.setVisibility(View.GONE);
listContent.team_logo2.setImageResource(android.R.drawable.ic_delete);
}
//@Override
public void onLoadingComplete(Bitmap loadedImage)
{
listContent.progress_team2.setVisibility(View.GONE);
Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
listContent.team_logo2.setAnimation(anim);
anim.start();
}
//@Override
public void onLoadingCancelled()
{
// Do nothing
}
public void onLoadingComplete() {
}
});
return convertview;
}
private class ListContent
{
ImageView team_logo1, team_logo2;
ProgressBar progress_team1,progress_team2;
}
}
This is my logcat:
FATAL EXCEPTION: main
java.lang.RuntimeException: ImageLoader must be init with configuration before using
at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:164)
at com.huskerit.score.CustomAdapter.getView(CustomAdapter.java:100)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220)
at android.widget.AbsListView.obtainView(AbsListView.java:1554)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1288)
at android.widget.ListView.onMeasure(ListView.java:1199)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:701)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:844)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
I have added this line in my Constructor and its worked for me...
imageLoader.init(ImageLoaderConfiguration.createDefault(context));