I have this method inside an Activity which implements an ImageLoader class:
public void imageLazy(final ImageView image,Project pro)
{
String imageurl = pro.smallImageUrl;
imageLoadery.displayImage(imageurl, activity,image);
}
but every time I run the Activity, the app crashed. There's a return null pointer on this line
imageLoadery.displayImage(imageurl, activity,image);
and it refers to the first line on this method on ImageLoader class:
if(((String)photoToLoad.imageView.getTag()).equals(photoToLoad.url)){
BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad.imageView);
Activity a=(Activity)photoToLoad.imageView.getContext();
a.runOnUiThread(bd);
}
All I know, what maybe null ist: tag, url, or image.
FYI, the method above is also applied in my listview adapter below. Maybe this can be a reference to help you to solve my case:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Inflate the view
if (convertView == null) {
convertView = mInflater.inflate(resource, null);
holder = new ViewHolder();
holder.image = (ImageView) convertView.findViewById(R.id.image);
holder.textTitle = (TextView) convertView
.findViewById(R.id.txt_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Project project = items.get(position);
holder.textTitle.setText(project.project_title);
String imageurl = project.smallImageUrl;
holder.image.setTag(imageurl);
imageLoader.displayImage(imageurl, activity, holder.image);
return convertView;
}
What makes it difficult for me, the method in ListView Adapter apply layout inflater for the Tag, which I barely need on my activity above.
Updated
Stacktrace:
05-16 09:02:00.758: INFO/System.out(441): http://cdn.spendino.de/web/img/projects/home/1263830540.jpg
05-16 09:02:00.769: INFO/System.out(441): spendino.de.Main@43d17ab0
05-16 09:02:00.778: INFO/System.out(441): android.widget.ImageView@43d041f0
05-16 09:02:00.778: INFO/System.out(441): http://cdn.spendino.de/web/img/projects/home/1263997113.jpg
05-16 09:02:00.801: INFO/System.out(441): spendino.de.Main@43d17ab0
05-16 09:02:00.829: INFO/System.out(441): android.widget.ImageView@43d17bd0
05-16 09:02:00.829: INFO/System.out(441): http://cdn.spendino.de/web/img/projects/home/1290615697.jpg
05-16 09:02:00.829: INFO/System.out(441): spendino.de.Main@43d17ab0
05-16 09:02:00.829: INFO/System.out(441): android.widget.ImageView@43d18098
05-16 09:02:01.398: INFO/ActivityManager(33): Displayed activity spendino.de/.Main: 3891 ms (total 3891 ms)
05-16 09:02:01.948: WARN/dalvikvm(441): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
05-16 09:02:01.958: ERROR/AndroidRuntime(441): Uncaught handler: thread Thread-9 exiting due to uncaught exception
05-16 09:02:01.978: ERROR/AndroidRuntime(441): java.lang.NullPointerException
05-16 09:02:01.978: ERROR/AndroidRuntime(441): at spendino.de.ImageLoaderCache$PhotosLoader.run(ImageLoaderCache.java:244)
imageLoadery.displayImage(imageurl, activity,image);put these linesSystem.out.println(imageurl);System.out.println(activity);System.out.println(image);and let me know the outputif(((String)photoToLoad.imageView.getTag()).equals(photoToLoad.url)){BitmapDisplayer bd=new BitmapDisplayer(bmp,photoToLoad.imageView); Activity a=(Activity)photoToLoad.imageView.getContext(); a.runOnUiThread(bd);}....... Print the out put ofphotoToLoad.imageView.getTag(),photoToLoad.url,imageView,bd