Tom Tom - 1 month ago 14
JSON Question

Error 404 while senting data to server

This is my code...

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

getResults();
StringRequest request= new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}){
protected Map<String,String>getParams() throws AuthFailureError{
Map<String,String> parameters = new HashMap<String, String>();
getResults().put(parameters);
return parameters;

}
};
requestQueue.add(request);


}
});
}


private JSONArray getResults() {

String myPath = "/data/data/com.example.sebastian.patientdetails/databases/" + "MyDBName.db";

String myTable = "patients";


SQLiteDatabase myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

String searchQuery = "SELECT * FROM " + myTable;
Cursor cursor = myDataBase.rawQuery(searchQuery, null);

JSONArray resultSet = new JSONArray();

cursor.moveToFirst();
JSONArray jsonArray = null;
while (!cursor.isAfterLast()) {

int totalColumn = cursor.getColumnCount();
JSONObject rowObject = new JSONObject();

jsonArray = new JSONArray();
for (int i = 0; i < totalColumn; i++) {
if (cursor.getColumnName(i) != null) {

JSONObject object = new JSONObject();
try {
if (cursor.getString(i) != null) {
Log.d("TAG_NAME", cursor.getString(i));
object.put(cursor.getColumnName(i), cursor.getString(i));

} else {
object.put(cursor.getColumnName(i), "");
}

jsonArray.put(object);
} catch (Exception e) {
Log.d("TAG_NAME", e.getMessage());
}
}
}

jsonArray.put(rowObject);
resultSet.put(rowObject);
cursor.moveToNext();
}


return resultSet;
}


}


This code i m using to sent my json array value to the server. When i click the button i got the error 'Unexpected response code 404'. Whats the problem, How can i solve it?Please help how can i solve it.? Is it an error from the server side.?

Answer

404 means the server not found. Make sure that you have entered the server path correctly. Make sure that you ve not included unwanted ' / ' s...