title: Retrieve Json object in android using volley
body: <p>Trying to get a value from my PHP API, on android, using volley... my API is working fine, returning the value I want, but on my android I can seem to save the value on a variable.</p>
  <p>this is my PHP script</p>
  <pre><code>&lt;?php
  
  if($_SERVER['REQUEST_METHOD']=='POST'){
  
  $titu = $_POST['titulo'];
  $id_use = $_POST['id_user'];
  $difi = $_POST['dificuldade'];
  
  
  $user = &quot;root&quot;;
  $pass = &quot;&quot;;
  $host= &quot;localhost&quot;;
  $dbname=&quot;check&quot;;
  
  $con = mysqli_connect($host,$user,$pass,$dbname);
  $sql=&quot;insert into trilhos(titulo,id_user,dificuldade) 
  values('&quot;.$titu.&quot;','&quot;.$id_use.&quot;','&quot;.$difi.&quot;');&quot;;
  
  
  $r = mysqli_query($con,$sql);
  
  $id_trilho =mysqli_insert_id($con);
  
  $result = array();
  echo json_encode(array(&quot;result&quot;=&gt;$id_trilho));
  
  mysqli_close($con);
  }
  </code></pre>
  <p>on my android studio, I try to get the value like this, I send 3 values to insert into the database, and then I want to return the id of the row I inserted back to android. I have looked at many answers on StackOverflow but I just can't seem to understand and solve my problem.</p>
  <pre><code>public void insert(String titulo, String id_trilho, String dif) {
      url = &quot;http://192.168.1.68/loginsignup/insertTrilho.php?titulo=&quot; + titulo +&quot;&amp;id_user=&quot;+ id_trilho+ &quot;&amp;dificuldade=&quot; + dif + &quot;&quot;;
      Log.i(&quot;Http&quot;, &quot;&quot; + url);
      RequestQueue requestQueue = Volley.newRequestQueue(InserirTrilho.this);
      StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener&lt;String&gt;() {
          @Override
          public void onResponse(String response) {
              try {
                  JSONObject jsonObject = new JSONObject(response);
                  JSONArray jsonArray = jsonObject.getJSONArray(&quot;result&quot;);
                  JSONObject jsonObject1 = jsonArray.getJSONObject(0);
                  String id = jsonObject1.getString(&quot;id_trilho&quot;);
                  Toast.makeText(InserirTrilho.this, id, Toast.LENGTH_SHORT).show();
  
  
                  SharedPreferences shared_id = getSharedPreferences(&quot;Mytrilho&quot;, Context.MODE_PRIVATE);
                  SharedPreferences.Editor editor = shared_id.edit();
                  editor.putString(&quot;id&quot;, id);
  
  
                  editor.commit();
                  Intent intent = new Intent(InserirTrilho.this, MapsActivity.class);
                  startActivity(intent);
  
              } catch (JSONException e) {
                  e.printStackTrace();
                  Toast.makeText(InserirTrilho.this, &quot;Dados Errados&quot;, Toast.LENGTH_SHORT).show();
              }
          }
      }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              Log.i(&quot;HttpError&quot;,&quot;erro&quot;+error);
          }
  
      });
      requestQueue.add(stringRequest);
  }
  </code></pre>
  <p>keep getting a thrown exception, can someone help me out, thank you in advance</p>