0


I have a problem. I can't seem to download a .jpg image from a URL source and then set it into a imageview which is inside a listview. It gives me the error "NullPointerException". I am currently using the ImageDownloader class from here.

This are the lines of code where i download the image files:
onCreate()...

        for (int i = 0; i < listData.size(); i++) {
            imageISBN = listData.get(i).get("coverImage");
            String isbnURL = "http://lib.syndetics.com/index.aspx?isbn=" + imageISBN + 
                                   "/SC.GIF&client=tpoly&type=xw12";
            ImageView iv = (ImageView) findViewById(R.id.cover_image);
            imageDownloader.download(isbnURL,iv);
        }

I'm thinking that it maybe due to my setContentView(R.layout.list) that's producing the error since it is just a listview and the imageview link is in another xml file.

Below is the LogCat:

05-11 09:26:58.063: ERROR/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.TPLibrary/com.TPLibrary.Search.SearchResults}: java.lang.NullPointerException 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.os.Handler.dispatchMessage(Handler.java:99) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.os.Looper.loop(Looper.java:123) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at java.lang.reflect.Method.invokeNative(Native Method) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at java.lang.reflect.Method.invoke(Method.java:521) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at dalvik.system.NativeStart.main(Native Method) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): Caused by: java.lang.NullPointerException 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.ImageDownloader.forceDownload(ImageDownloader.java:80) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.ImageDownloader.download(ImageDownloader.java:49) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at com.TPLibrary.Search.SearchResults.onCreate(SearchResults.java:185) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 05-11 09:26:58.063: ERROR/AndroidRuntime(305): ... 11 more

So guys, any ideas? Could it be that i'm using the ImageDownloader class wrongly?

Joel Seah
  • 674
  • 3
  • 13
  • 34

1 Answers1

0

In ImageDownloader class, the mode is assigned to NO_ASYNC_TASK:

public enum Mode { NO_ASYNC_TASK, NO_DOWNLOADED_DRAWABLE, CORRECT }
private Mode mode = Mode.NO_ASYNC_TASK;

Your intention was to download the image. So try setting the mode variable to NO_DOWNLOADED_DRAWABLE.

faradaj
  • 3,629
  • 1
  • 22
  • 21
  • hey, thanks for your reply. I tried your answer and it didn't really work. I believe its due to my imageView having a nullpointerexception. I'm using a simpleadapter to display my list of data with imageviews instead of using a adapterclass like from the link above. So is there anyway for me to link my ImageLoader class's imageview to my xml's imageview? – Joel Seah May 11 '11 at 09:09
  • You should try making ImageDownlader a subclass of SearchResults. Then define your ImageView in the scope of SearchResults. (you may want to initialize this variable in SearchResult's onCreate()) Then you will be able to see if is there a problem whether inside classes or linking the ImageView. – faradaj May 13 '11 at 16:31