Null Pointer Exception In Method
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I designed app to make order for pizza food restaurant
I show userid,menu id ,address,longtiude,latitude then press on button make order
Error show after I press button and found in async task doin background
It give me fatal exception error
An error occurred while executing doInBackground()
and it show to me two lines have proplem
AddNewOrder.doInBackground(Summary.java:113)
AddNewOrder.doInBackground(Summary.java:77)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.json.JSONObject.getBoolean(java.lang.String)' on a null object reference
Class AppConfig
json parser
I show userid,menu id ,address,longtiude,latitude then press on button make order
Error show after I press button and found in async task doin background
It give me fatal exception error
An error occurred while executing doInBackground()
and it show to me two lines have proplem
AddNewOrder.doInBackground(Summary.java:113)
AddNewOrder.doInBackground(Summary.java:77)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean org.json.JSONObject.getBoolean(java.lang.String)' on a null object reference
Class AppConfig
json parser
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Your makeHttpRequest() call is returning a null object.
I can't really tell why as I can't follow the flow of the code to see what is happening, as the code is completely unformatted.
Is your original code really unindented like that?
Can I suggest reposting that JSONParser class but with proper formatting? Don't worry about the other classes for now.
Anyway, is there anything else in the logs that will tell you what has happened inside that method?
I see lots of logging, so you should be able to trace the route it took.
I can't really tell why as I can't follow the flow of the code to see what is happening, as the code is completely unformatted.
Is your original code really unindented like that?
Can I suggest reposting that JSONParser class but with proper formatting? Don't worry about the other classes for now.
Anyway, is there anything else in the logs that will tell you what has happened inside that method?
I see lots of logging, so you should be able to trace the route it took.
ahmed abed elaziz
Greenhorn
Posts: 9
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
json parser class based on your request
The error i show to me is is
json parser End of input at character 0 of
after i run code below as you mention before
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
The error i show to me is is
json parser End of input at character 0 of
after i run code below as you mention before
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
Dave Tolls
Rancher
Posts: 4801
50
posted 9 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That's still unformatted.
There's no indentation.
So step 1 is to format it correctly.
Also, as I said, there's lots of logging in there so you should be able to post what the logs look like up to the error, at least the ones leading up to the exception.
You should also print the stack trace of the exception, which will be done automatically for you if you change your Log call to:
You should do that for all your catch blocks.
One thing I will note is that it looks to me like you continue processing if the load attempt fails, which means that 'json' is unlikely to have anything in it at all.
There's no indentation.
So step 1 is to format it correctly.
Also, as I said, there's lots of logging in there so you should be able to post what the logs look like up to the error, at least the ones leading up to the exception.
You should also print the stack trace of the exception, which will be done automatically for you if you change your Log call to:
You should do that for all your catch blocks.
One thing I will note is that it looks to me like you continue processing if the load attempt fails, which means that 'json' is unlikely to have anything in it at all.
| Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






