Skip to content Skip to sidebar Skip to footer

Cannot List The Data In My Android Application From Mysql

Am new in Android development. I trying to do database CRUD operation in my android application. I can successfully insert the data to the mysql.Am

Solution 1:

Error parsing data org.json.JSONException: Value get_all_products.phpoftype java.lang.String cannot be converted to JSONObject

states that you don't have valid json string in your resopnse coming from web service. Becuase of this jObj = isValidJson(json); doesn't return any json object.

In your above code, at

json = sb.toString();

You are creating String named as json and assign string builder object value to it. But you logcat says that you are not geeting valid json string at below line,

try {
                        jObj = newJSONObject(json);
                    } catch (JSONException e) {
                        Log.e("JSON Parser", "Error parsing data " + e.toString());
                    }

So it throws error about parsing json string. In this case you have to check whether you go t valid json string from server in response. Make some changes in above code:

publicbooleanisValidJson(String test)
{
    try {
        newJSONObject(test);
        returntrue;
    } catch(JSONException ex) { 
        returnfalse;
    }
}

And, in your code:

try {
       if(isValidJson(json)
    {
      jObj = newJSONObject(json);
    } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
    } 

Post a Comment for "Cannot List The Data In My Android Application From Mysql"