I am a beginner for Java Coding and is currently coding an Android Project. Right now, I am facing an issue. The data retrieved is not showing up in the textviews.
My plan is to retrieve the details using the vehicle number from the intent. After which, the details will be shown in the textviews. I've checked, the php is showing the information i need, which means that it is the java that is having problem. However, i'm unable to spot the mistake. Please advice me or provide me with some examples. Thank you.
package com.example.maptesting;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
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.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class NextActivity extends Activity {
TextView vehicle_no;
TextView resultSessionID;
TextView resultPartial;
RequestQueue requestQueue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
vehicle_no = (TextView) findViewById(R.id.vehicle_no);
Intent intent = getIntent();
String veh_no = intent.getStringExtra("vehicleno");
vehicle_no.setText(veh_no);
requestQueue = Volley.newRequestQueue(getApplicationContext());
String url = ("http://mp60.bas-mp.bus/testingtesting/showPartialDetails.php?vehicle_no=" + vehicle_no.getText().toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray students = response.getJSONArray("students");
for (int i = 0; i < students.length(); i++) {
JSONObject parkingsession = students.getJSONObject(i);
String parkingsession_id = parkingsession.getString("parkingsession_id");
String datetime_start = parkingsession.getString("datetime_start");
String datetime_end = parkingsession.getString("datetime_end");
String duration = parkingsession.getString("duration");
String charges = parkingsession.getString("charges");
resultSessionID = (TextView) findViewById(R.id.parkingsessionID);
resultSessionID.append(parkingsession_id);
resultPartial = (TextView) findViewById(R.id.details1);
resultPartial.append("Session Start:" + datetime_start + "\n"+
"Session End:" + datetime_end + "\n"+
"Duration:" + duration + "\n"+
"Total Charges:" + charges + "\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}
}