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

digital signature with php on excel
$_GET in frinedly url (.htaccess) isn't working
Is there a way to test my nonce validation fails when it should?
While in zend framework
Php Split text from html text area
Drupal custom registration Form element not showing on frontend
Modsecurity CSRF alert when using $_GET
.htaccess Rewrite - traffic to a folder to resolve to one of it's subfolders without changing URL
php: writing to file using fputcsv messes up format
php get domain from url and ignore subdomains
Incorrect results obtained in simple arithematic using php
make sure atleast one checkbox is selected php
Laravel: how can I get the result from eager loading?
PHP: Getting a Proper escaped String from json_encode
php function variables not getting passed
Can't figure out how to associate tables with php active record

Categories

HOME
php
cocoapods
functional-programming
facebook-messenger
bokeh
swi-prolog
haproxy
adobe
typeerror
docker-cloud
save
u-boot
mutation-testing
sap-fiori
csrf
vimeo
fullcalendar-scheduler
createjs
mpu6050
django-rq
asp.net-core-1.0
fresco
bnf
android-5.1.1-lollipop
home
tableview
kaggle
generator
websphere-portal
hevc
running-object-table
ruby-daemons
ninject
epplus
seafile-server
formsauthenticationticket
cordys-opentext
google-now
oauth2-playground
classnotfoundexception
fiware-wirecloud
google-prediction
dbcc
web-inspector
zend-form
adblock
rightnow-crm
simple-schema
cognos-tm1
nrf51
oracle-fusion-apps
mathjs
callouts
qtcpsocket
simian
vaadin4spring
utf-16
gulp-uglify
json-spirit
outlook.com
boost-proto
bayesglm
srv-record
apple
360-degrees
search-form
google-gdk
algebraixlib
dbmigrate
web-api
console.log
nssortdescriptor
rfc5545
sablecc
findersync
fat32
configurable-product
cout
nidaqmx
coding-efficiency
screwturn
.htpasswd
refit
zend-search-lucene
particle-swarm
libxml-js
form-for
axacropdf
xalan
zend-pdf
nsfont
algol68
sql-parametrized-query
ognl
eaccelerator
ios-4.2
pinax
processors
main-method
ntruencrypt

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App