Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task

Null Pointer Exception In Method Boolean.Org.Json.Jsonobject Do in background async task

Scheduled Pinned Locked Moved Android
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed_sa
    wrote on last edited by
    #1

    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 package com.pizza_final_project_app.pizza_final_project; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; public class Summary extends Activity { SharedPreferences preferences; private ProgressDialog pDialog; //JSONParser jsonParser = new JSONParser(); boolean errorFound; TextView textaddress; TextView textlongtiude; TextView textlatitude; TextView text2; TextView textuser; Button btnorder; private static final String TAG_SUCCESS = "success"; private static final String TAG = Summary.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_summary); text2=(TextView)findViewById(R.id.textView3); textaddress=(TextView)findViewById(R.id.textaddress); textuser=(TextView)findViewById(R.id.textView4); textlongtiude=(TextView)findViewById(R.id.textlongtiude); textlatitude=(TextView)findViewById(R.id.textlatitude); Intent i = getIntent(); String id = i.getStringExtra("Data4"); String address = i.getStringExtra("Data8"); String longtiude = i.getStringExtra("Data9"); String latitude = i.getStringExtra("Data10"); text2.setText(id); textaddress.setText(address); textlongtiude.setText(longtiude); textlatitude.setText(latitude); preferences= PreferenceMana

    D L 2 Replies Last reply
    0
    • A ahmed_sa

      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 package com.pizza_final_project_app.pizza_final_project; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; public class Summary extends Activity { SharedPreferences preferences; private ProgressDialog pDialog; //JSONParser jsonParser = new JSONParser(); boolean errorFound; TextView textaddress; TextView textlongtiude; TextView textlatitude; TextView text2; TextView textuser; Button btnorder; private static final String TAG_SUCCESS = "success"; private static final String TAG = Summary.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_summary); text2=(TextView)findViewById(R.id.textView3); textaddress=(TextView)findViewById(R.id.textaddress); textuser=(TextView)findViewById(R.id.textView4); textlongtiude=(TextView)findViewById(R.id.textlongtiude); textlatitude=(TextView)findViewById(R.id.textlatitude); Intent i = getIntent(); String id = i.getStringExtra("Data4"); String address = i.getStringExtra("Data8"); String longtiude = i.getStringExtra("Data9"); String latitude = i.getStringExtra("Data10"); text2.setText(id); textaddress.setText(address); textlongtiude.setText(longtiude); textlatitude.setText(latitude); preferences= PreferenceMana

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Post only relevant code next time. The error text plainly states that jObj is null.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

      A N 2 Replies Last reply
      0
      • D David Crow

        Post only relevant code next time. The error text plainly states that jObj is null.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        A Offline
        A Offline
        ahmed_sa
        wrote on last edited by
        #3

        to remove error what i make

        1 Reply Last reply
        0
        • A ahmed_sa

          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 package com.pizza_final_project_app.pizza_final_project; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; public class Summary extends Activity { SharedPreferences preferences; private ProgressDialog pDialog; //JSONParser jsonParser = new JSONParser(); boolean errorFound; TextView textaddress; TextView textlongtiude; TextView textlatitude; TextView text2; TextView textuser; Button btnorder; private static final String TAG_SUCCESS = "success"; private static final String TAG = Summary.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_summary); text2=(TextView)findViewById(R.id.textView3); textaddress=(TextView)findViewById(R.id.textaddress); textuser=(TextView)findViewById(R.id.textView4); textlongtiude=(TextView)findViewById(R.id.textlongtiude); textlatitude=(TextView)findViewById(R.id.textlatitude); Intent i = getIntent(); String id = i.getStringExtra("Data4"); String address = i.getStringExtra("Data8"); String longtiude = i.getStringExtra("Data9"); String latitude = i.getStringExtra("Data10"); text2.setText(id); textaddress.setText(address); textlongtiude.setText(longtiude); textlatitude.setText(latitude); preferences= PreferenceMana

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I have no intention of trying to plough through that unformatted code dump. However, it is highly likely that the following line did not return an object:

          JSONObject jObj = jsonParser.makeHttpRequest(AppConfig.URL_Order, "POST", params);

          1 Reply Last reply
          0
          • D David Crow

            Post only relevant code next time. The error text plainly states that jObj is null.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #5

            don't forget: use "pre" tags to format it

            M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups