php


.NullPointerException while retrieving data with volley


i am trying to retrieve data with volley but i keep getting this error:
This is my json file which is accessed with this link "http:/192.168.1.4/pim/get_all_bus.php" where 192.168.1.4 is my local ip address
{
"Bus": [
{
"id_bus": "3",
"name_bus": "51A",
"terminusDepart": "Ennasr1",
"terminus_arrivee": "TGM"
},
{
"id_bus": "4",
"name_bus": "51A",
"terminusDepart": "Ennasr2",
"terminus_arrivee": "tunis"
}
],
"success": 1
}
the error that i am getting is this
04-09 14:40:00.589 5256-5256/info.androidhive.volleyexamples E/AndroidRuntime: FATAL EXCEPTION: main
Process: info.androidhive.volleyexamples, PID: 5256
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.JsonRequest.<init>(JsonRequest.java:58)
at com.android.volley.toolbox.JsonArrayRequest.<init>(JsonArrayRequest.java:42)
at info.androidhive.volleyexamples.JsonRequestActivity.makeJsonArryReq(JsonRequestActivity.java:111)
at info.androidhive.volleyexamples.JsonRequestActivity.onClick(JsonRequestActivity.java:146)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
the function that i am using is this one :
private void makeJsonArryReq() {
showProgressDialog();
JsonArrayRequest req = new JsonArrayRequest("http:/192.168.1.4/pim/get_all_bus.php",
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
msgResponse.setText(response.toString());
//msgResponse.setText(response.toString());
hideProgressDialog();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(req,
tag_json_arry);
// Cancelling request
// ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_arry);
}
Here you need to call JsonObjectRequest first. Your given link, returns a json object. After getting the json object, you need to parse the data.
Quick tip. In the JSON format curly brackets "{}" defines an object and third brackets "[]" defines an array.
Now look at the response from your PHP script. It starts with a curly bracket. That means your response is a JSON object. Therefore, you need to call a JSONObjectRequest from volley and not a JSONArrayRequest.

Related Links

single-{post-type}.php is not working in wordpress
Multiple post parts in same page
PHP Method Chaining without writing lots of return this
how do i reference a dynamically created list php
Laravel Request show what form the input was captured in
Json data getting read but not inserting into mysql using php
phpunit Mock returns null while original method returns string
How to search for affinity score for audience insight affinity?
Laravel queues in local and production
Doctrine criteria comparing object id to integer
Trouble running Laravel 5 Server. “Whoops, looks like something went wrong.” http://127.0.0.1:8000/
save image in public folder instead storage laravel 5
Need to check login fields from two tables [duplicate]
variable not inserted to table [duplicate]
Yii2 GridView SqlDataprovider sort not working
Converting String Date To Carbon Timestamp with Locale

Categories

HOME
events
list
opencart
clearcase
antd
informatica
bing-search
docker-cloud
lvm
ipv6
telegraf
circleci
vimeo
jquery-select2-4
jquery-file-upload
django-rq
orange-api
twisted
significance
anova
sharedpreferences
connection-refused
bonita
jsonresult
premake
rust-cargo
cloveretl
image-optimization
nsuserdefaults
cordys-opentext
djcelery
identify
unification
django-smart-selects
tidal-scheduler
microkernel
export-to-pdf
plane
hypothesis-test
web-inspector
morphline
sendinput
docker-ucp
react-intl
audio-converter
rm
brightscript
non-linear-regression
renderman
maven-jaxb2-plugin
google-news
gnome-terminal
test-data
http-basic-authentication
mpmovieplayercontroller
kendo-treeview
perl-data-structures
haraka
rational-performance-test
okio
logical
jenkins-workflow
cdo.message
wolfram-language
fragmentstatepageradapter
dojo-build
right-to-left
meld
uibinder
jeditable
diawi
phpquery
boost-proto
smart-tv
largenumber
hmisc
embeddedwebserver
actionpack
python-curses
python-c-extension
thoughtworks-go
vs-unit-testing-framework
wicket-1.5
iodocs
image-rotation
mobile-country-code
boolean-algebra
gpu-programming
property-injection
smips
jmenubar
visual-c++-2005
xalan
arrow
sfinae
telerik-ajax
pageheap
zotonic
java.lang.class
hardcode
nsfont
algol68
fbml
zend-server-ce
pyjamas
rational-unified-process
ning
datagridcolumn
gui-designer
bindable-linq
parentid

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App