cant show the total amount of this equation using php which is json encoded to a textview in android studio
here is the equation in php
$d=2;
$d0=(($b1*2*9)+($b2*3) + (4*$b3))-(($b1*4*3)+($b2*9)+(2*$b3));
$d1 = (($b1 * 4) + ($b2 * 9) + ($b3)) - (($b1 * 9) + ($b2) + (4 * $b3));
$d2 = (($b1 * 3) + ($b2) + (2 * $b3)) - (($b1 * 2) + ($b2 * 3) + ($b3));
$a0 = $d0 / $d;
$a1 = $d1 / $d;
$a2 = $d2 / $d;
$tot = $a0 + ($a1 * 4) + ($a2 * 16);
$format = new \stdClass();
$format->predicted=number_format($tot, 2);
$json = json_encode($format);
echo $json;
Note* $b1, $b2 and $b3 are data from mysql.
The output is this
{"predicted":"35,370,362.30"}
now the code in android studio which is getting the string predicted in json is this. the code is working on my other module tho. I think the php file has the problem her
public GetTextViewData(Context context)
{
this.context = context;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0)
{
HttpClient myClient = new DefaultHttpClient();
HttpPost myConnection = new HttpPost("http://10.0.2.2/sample/prediction.php");
try {
response = myClient.execute(myConnection);
str = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try{
JSONArray jArray = new JSONArray(str);
json = jArray.getJSONObject(0);
} catch ( JSONException e) {
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result)
{
try {
tv1.setText(json.getString("predicted"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
this line is the error in my code
tv1.setText(json.getString("predicted"));