1. Software Account's Avatar
    I have the below code which returns the FirstName, LastName and Class of student stored in database in json format. But when I run the app, data is not displayed
    ~~~~
    package com.example.anitaa.student;

    import android.app.DownloadManager;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.android.volley.Request;
    import com.android.volley.RequestQueue;
    import com.android.volley.Response;
    import com.android.volley.VolleyError;
    import com.android.volley.toolbox.JsonObjectRequest;
    import com.android.volley.toolbox.JsonRequest;
    import com.android.volley.toolbox.StringRequest;
    import com.android.volley.toolbox.Volley;

    import org.json.JSONException;
    import org.json.JSONObject;

    public class MainActivity extends AppCompatActivity {
    TextView FirstName;
    TextView LastName;
    TextView Class;
    Button b1;
    String url1="http://192.168.1.3/student/web/studentrecords";

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    FirstName=(TextView) findViewById(R.id.firstname1);
    LastName=(TextView) findViewById(R.id.lastname1);
    Class=(TextView) findViewById(R.id.class1);
    b1=(Button) findViewById(R.id.btn3);
    b1.setOnClickListener(new View.OnClickListener() {
    @override
    public void onClick(View v) {
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.POST, url1, null, new Response.Listener<JSONObject>() {
    @override
    public void onResponse(JSONObject response) {
    try {
    FirstName.setText( response.getString ( "FirstName").toString ());
    LastName.setText(response.getString("LastName").toString ());
    Class.setText(response.getString("Class").toString());
    } catch (JSONException e) {
    e.printStackTrace();
    }
    }
    }, new Response.ErrorListener() {
    @override
    public void onErrorResponse(VolleyError error) {
    Toast.makeText(MainActivity.this, error.getMessage(),Toast.LENGTH_SHORT).show();
    error.printStackTrace();

    }
    });
    MySingleton.getInstance(MainActivity.this).addToRequestque(jsonObjectRequest);
    }

    });
    }
    }
    ~~~~

    Exception is displayed as

    ~~~~
    org.json.JSONExcetion: Value null of type org.json.JSONObject$1 cannot be converted to JSONObject
    ~~~~

    What should I do?
    07-17-2019 11:10 AM
  2. hallux's Avatar
    Would you rather this be moved to the developers lounge where folks that do this kind of stuff hang out? @B. Diddy can help with that...
    ManiacJoe and B. Diddy like this.
    07-17-2019 05:48 PM
  3. Rukbat's Avatar
    Move to Software Development. It won't get much exposure in a general purpose forum.
    B. Diddy likes this.
    07-17-2019 06:39 PM

Similar Threads

  1. How can I free up space using the Huawei gallery app?
    By Lucy Davies in forum Huawei P20 & P20 Pro
    Replies: 46
    Last Post: 09-02-2019, 09:39 PM
  2. Every time i plug in for charging. 1 pop is coming. Whats the solution
    By Android Central Question in forum Ask a Question
    Replies: 2
    Last Post: 07-17-2019, 09:21 PM
  3. Why is face app isnt working in oppo f9 with ram 6 gb
    By Android Central Question in forum Ask a Question
    Replies: 2
    Last Post: 07-17-2019, 09:18 PM
  4. How to restore backup app from pc to another android mobile phone?
    By Android Central Question in forum Ask a Question
    Replies: 6
    Last Post: 07-17-2019, 09:14 PM
LINK TO POST COPIED TO CLIPBOARD