Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Error in String cannot be converted to JSONArray

Jiaen Ong:

I have a list of image that i get from server and i place it in the listView and it works fine, but in the subjectActivity class, i try to use the below php to call and display the detail of the image, it display the error below. I will be appreciated if anyone can help me.


12-24 16:05:19.858 2177-2177/com.example.user.arlearn W/System.err: com.android.volley.ParseError: org.json.JSONException: Value
12-24 16:05:19.858 2177-2177/com.example.user.arlearn W/System.err: at com.android.volley.toolbox.JsonArrayRequest.parseNetworkResponse(JsonArrayRequest.java:70)
12-24 16:05:19.858 2177-2177/com.example.user.arlearn W/System.err: at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:123)
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: Caused by: org.json.JSONException: Value
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: at org.json.JSONArray.(JSONArray.java:96)
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: at org.json.JSONArray.(JSONArray.java:108)
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: at com.android.volley.toolbox.JsonArrayRequest.parseNetworkResponse(JsonArrayRequest.java:65)
12-24 16:05:19.859 2177-2177/com.example.user.arlearn W/System.err: ... 1 more


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {

Intent intent = new Intent(getActivity(), SubjectActivity.class);
startActivity(intent);
}
});


include("connection1.php");

// connecting to db
$conn = mysqli_connect($hostname_localhost, $username_localhost, $password_localhost, $database_localhost);

/* check connection */
if (mysqli_connect_errno()) {
echo "Error: Connect failed: %s\n";
exit();
}

$response = array();

$id=$_GET['subjectID'];

$query = "SELECT image, name, Description1, Description2 from subject WHERE subjectID = ".$id;


/* Select queries return a resultset */
if ($result = mysqli_query($conn, $query))
{
$response = array();

while ($row = mysqli_fetch_array($result))
{
$item = array();
$item["image"] = base64_encode($row["image"]);
$item["name"] = $row["name"];
$item["Description1"] = $row["Description1"];
$item["Description2"] = $row["Description2"];
array_push($response, $item);
}
mysqli_free_result($result);
}

echo json_encode($response);
/* close connection */
mysqli_close($conn);
?>



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Error in String cannot be converted to JSONArray

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×