Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Null Pointer Exception In Method

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 4786
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4786
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic