这是我的代码......
b2 = (Button) findViewById(R.id.button3);
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();
//new jsonarray
jsonArray = new JSONArray();
for (int i = 0; i < totalColumn; i++) {
if (cursor.getColumnName(i) != null) {
//new jsonarray of items jsonObject
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), "");
}
//put jsonarray
jsonArray.put(object);
} catch (Exception e) {
Log.d("TAG_NAME", e.getMessage());
}
}
}
//put request jsonobject
jsonArray.put(rowObject);
resultSet.put(rowObject);
cursor.moveToNext();
}
return jsonArray;
}
}
当我单击按钮将我的json对象发送到服务器时,我收到此错误'意外响应代码500'。什么原因。我该如何解决这个问题。将我的sqlite转换为json对象是否有任何问题。?
答案 0 :(得分:2)
Web服务器(运行Web站点)遇到意外情况,导致客户端(例如您的Web浏览器或CheckUpDown机器人)无法满足请求访问请求的URL的请求。
这是Web服务器生成的“全能”错误。基本上出了问题,但服务器在响应客户端时不能更具体地说明错误情况。除了通知回客户端的500错误之外,Web服务器还应生成某种内部错误日志,其中提供了更多错误的详细信息。由Web服务器站点的操作员来定位和分析这些日志。