0

This is my code...

      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;
}


}

When i click the button to sent my json object to server i got this error ' Unexpected response code 500 ' . Whats the reason. How can i fix this issue. Is there any issue in converting my sqlite to json object.?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Please check the null before passing the parameter. – LoveAndroid Oct 28 '16 at 05:36
  • @LoveAndroid how can i do it.. can you explain.? –  Oct 28 '16 at 05:41
  • 2
    Why are you calling `getResults();`? It **returns** a value, but you do nothing with that value – OneCricketeer Oct 28 '16 at 05:42
  • 2
    That basically means the server at the other end could not process your message, perhaps due to misformed data. Please post your LogCat, if that contains additional information. – Ken Y-N Oct 28 '16 at 05:45
  • 2
    Anyways, 500 internal server error. If you want the reason, you have to go look at the server – OneCricketeer Oct 28 '16 at 05:45
  • Is there any problem with my code.? –  Oct 28 '16 at 05:51
  • 1
    `getResults().put(parameters);` doesn't do what you hope it does - that adds `parameters` to the result of the function, then throws everything away, when I think you actually want to copy the data out of `getResults()` into `parameters`. – Ken Y-N Oct 28 '16 at 05:53
  • Possible duplicate of [Convert a JSON String to a HashMap](http://stackoverflow.com/questions/21720759/convert-a-json-string-to-a-hashmap) – Ken Y-N Oct 28 '16 at 05:55
  • @KenY-NHow can i do it.? –  Oct 28 '16 at 05:55
  • 1
    [See here](http://stackoverflow.com/a/39048250/1270789): `parameters = JsonUtils::toMap(getResults());` or so. – Ken Y-N Oct 28 '16 at 05:57
  • Can anybody edit my code and provide me a working code... I am new to android development –  Oct 28 '16 at 05:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126883/discussion-between-tom-and-ken-y-n). –  Oct 28 '16 at 06:09
  • 1
    This means that your app is sending the data which cannot understand by the server... – Sebastian Oct 28 '16 at 07:41

1 Answers1

2

The Web server (running the Web Site) encountered an unexpected condition that prevented it from fulfilling the request by the client (e.g. your Web browser or our CheckUpDown robot) for access to the requested URL.

This is a 'catch-all' error generated by the Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to the client. In addition to the 500 error notified back to the client, the Web server should generate some kind of internal error log which gives more details of what went wrong. It is up to the operators of the Web server site to locate and analyse these logs.

reference: http://www.checkupdown.com/status/E500.html

Kona Suresh
  • 1,836
  • 1
  • 15
  • 25