Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception In Method

 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dave Tolls
Ranch Hand
Posts: 2102
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ahmed abed elaziz
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
 
Dave Tolls
Ranch Hand
Posts: 2102
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic