vjdhama
vjdhama

Reputation: 5078

Volley image request error

I am getting this error with the image request using volley library. I am implementing custom listview using volley.

02-26 22:05:58.736: E/AndroidRuntime(19873): FATAL EXCEPTION: main
02-26 22:05:58.736: E/AndroidRuntime(19873): java.lang.NullPointerException
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.Request.<init>(Request.java:137)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:220)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:149)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:198)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.view.View.layout(View.java:14118)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
02-26 22:05:58.736: E/AndroidRuntime(19873): FATAL EXCEPTION: main
02-26 22:05:58.736: E/AndroidRuntime(19873): java.lang.NullPointerException
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.Request.<init>(Request.java:137)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:220)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:149)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:198)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.view.View.layout(View.java:14118)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
02-26 22:05:58.736: E/AndroidRuntime(19873): FATAL EXCEPTION: main
02-26 22:05:58.736: E/AndroidRuntime(19873): java.lang.NullPointerException
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.Request.<init>(Request.java:137)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:220)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:149)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:198)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.view.View.layout(View.java:14118)
02-26 22:05:58.736: E/AndroidRuntime(19873):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)

I am using networkImageView over simple imageview. The error seems to be due to the init function in the MyVolley class. And guess what? i am relatively new to networking. So don't mind throwing some pointers on that front.

All the code is in this gist.

Upvotes: 0

Views: 1334

Answers (2)

Itai Hanski
Itai Hanski

Reputation: 8690

Are you up to date with the commits in the Volley repository?

Recently a null pointer correction has been applied to line 137 in the Request class. Try updating the Volley repository and see if it persists.

Upvotes: 2

Udi Oshi
Udi Oshi

Reputation: 6867

If you are using ImageRequest you don't need NetworkImageView, ImageRequest will return for you the bitmap and just put it inside regular ImageView, but check first that bitmap isn't null, you are probably getting null bitmap and trying to put it inside your NetworkImageView.

To use NetworkImageView correctly just use the following function:

setImageUrl("http://someurl.com/image.png",mImageLoader);

You can see the following tutorial for more information about that.

Good luck

Upvotes: 0

Related Questions