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="";

    protected void onCreate(Bundle savedInstanceState) {
    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() {
    public void onClick(View v) {
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.POST, url1, null, new Response.Listener<JSONObject>() {
    public void onResponse(JSONObject response) {
    try {
    FirstName.setText( response.getString ( "FirstName").toString ());
    LastName.setText(response.getString("LastName").toString ());
    } catch (JSONException e) {
    }, new Response.ErrorListener() {
    public void onErrorResponse(VolleyError error) {
    Toast.makeText(MainActivity.this, error.getMessage(),Toast.LENGTH_SHORT).show();



    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 10: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 04: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 05: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, 08: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, 08: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, 08: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, 08:14 PM