Search code examples
androidimageloaderuniversal

An error when using the universal image loader


This is my first time using the Universal Image loader libary.

An error occurs when I use a button to trigger the display of a web image. The relevant codes looks like that:

public class MainActivity extends Activity {

ImageView iv;
Button btnButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    iv = (ImageView)findViewById(R.id.imageView1);
    btnButton = (Button)findViewById(R.id.button1);

    btnButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // dislpay a web image using a ImageView
            String url = "http://icons.iconarchive.com/icons/xenatt/minimalism/128/App-Json-Toolbox-icon.png";
             ImageLoader imageLoader = ImageLoader.getInstance();
            ImageLoaderConfiguration imgconfig = ImageLoaderConfiguration.createDefault(MainActivity.this);

            imageLoader.init(imgconfig);
            imageLoader.displayImage(url, iv);




        }
    });




}

However, the program crushed. Based on the logcat, I find the error information in this sentence:

ImageLoaderConfiguration imgconfig = ImageLoaderConfiguration.createDefault(MainActivity.this);

How can I fix this error?


Solution

  • You first initialize Image Loader in a class that extend of Application not ?

    And in the logcat what is the error exactly ?