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?