7

I'm trying to load images from URL into girdview using Volley Library. For this I'm following this tutorial. When I run my project, it collects all URLs from server database and then store in arraylist. But doesn't displays images. And I am getting java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference error. It doesn't even point to any line number of code where I'm getting this error. See below Logcat Output :

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
        at com.android.volley.Request.<init>(Request.java:136)
        at com.android.volley.toolbox.ImageRequest.<init>(ImageRequest.java:71)
        at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:219)
        at com.android.volley.toolbox.ImageLoader.get(ImageLoader.java:171)
        at com.android.volley.toolbox.NetworkImageView.loadImageIfNecessary(NetworkImageView.java:141)
        at com.android.volley.toolbox.NetworkImageView.onLayout(NetworkImageView.java:190)
        at android.view.View.layout(View.java:15596)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.GridView.setupChild(GridView.java:1542)
        at android.widget.GridView.makeAndAddView(GridView.java:1436)
        at android.widget.GridView.makeRow(GridView.java:361)
        at android.widget.GridView.fillDown(GridView.java:302)
        at android.widget.GridView.fillFromTop(GridView.java:437)
        at android.widget.GridView.layoutChildren(GridView.java:1276)
        at android.widget.AbsListView.onLayout(AbsListView.java:2148)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
        at android.widget.ScrollView.onLayout(ScrollView.java:1502)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:494)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
        at android.view.View.layout(View.java:15596)
        at android.view.ViewGroup.layout(ViewGroup.java:4966)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
        at android.view.Choreographer.doCallbacks(Choreographer.java:580)
        at android.view.Choreographer.doFrame(Choreographer.java:550)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Can anybody help me what is the exact problem and how do I solve this ?

Ruchir
  • 1,178
  • 3
  • 23
  • 44
  • 1
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Selvin Oct 13 '15 at 11:36
  • @Selvin No..This is not duplicate of What is Null pointer.... – Ruchir Oct 13 '15 at 11:38
  • 2
    You're calling #hashCode() on a null string. – nbokmans Oct 13 '15 at 11:42
  • 2
    @nbokmans why are you so sure that *he/she* calls it? I don't think the package name of his/her code would be `com.android...` – Sweeper Oct 13 '15 at 12:41

8 Answers8

8

You should check the null values for the image where you are getting the data from the server.

Avanish Singh
  • 258
  • 3
  • 8
4

Getting string value as null, for this instance shows String.hashcode() error

Gopi Cg
  • 314
  • 3
  • 7
0

I had same problem. Just found a fix I think. In the link to the server you are trying to communicate with, specify the protocol for communication i.e "http://" or "https://" before adding the domain and all. That fixed it for me. I hope it helps

Ata
  • 21
  • 2
0

I had this Error in another Content and fixed it by updating the Android SDK in Android Studio. Maybe it's helping.

Kay
  • 11
  • 1
0

My server is https and so was getting a different error. I removed the https and remained with the domain name only and it failed to work so I ended up putting up the https: and contacting my host to ease the security rules on the domain or create special provision for the specific domain. Check where you implement your site url and add http or https depending on how your site looks on browser.

0

Changing the api response (data classes) with appropriate @serializedName annotation.

Nitin Tej
  • 324
  • 1
  • 7
0

It is a very good possibility that the data model you are mapping the API response to is expecting a non-null String parameter that is missing entirely or null. This can be because you typed the param name incorrectly or the API assumes the param is optional.

DevinM
  • 860
  • 1
  • 7
  • 22
-3

Check up your manifest. make sure uses permission internet write up there.

Nanda R.M
  • 119
  • 2
  • 9