So I Googled and found examples similar to what i need. I've tweaked and adjusted and solved most of my problems but have become confounded by this problem which i cannot seem to pass. Some Backround: So I'm building an App that query's a MySQL data base through PHP producing a JSON object. I can see "[{"question":"Why is the sky blue"}]" in my web browser on the SDK so I know I have access to the object. Permissions are set properly in my manifest as well. The problem comes when i try to parse the object to a string. I get "Error converting result java.lang.NullPointerException" from my log cat.
Now I've tried
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String json = reader.readLine();
JSONTokener tokener = new JSONTokener(json);
JSONArray finalResult = new JSONArray(tokener);
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
I've also tried
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line="0";
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
I guess I'll post my http (even in its own thread best practices yay! - but then i use global variables (facepalm))
new Thread() {
public void run() {
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.55/qgrap.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
}
}.start();
In the HTTP for the second code set you need to do some get content stuff either way I'd like to focus on the first code set. Here response is a global variable. which gets manipulated as it gets passed into BufferReader arguments. I'f I'm not mistaken at the point of String json = reader.readLine(); I should have access to the data as a string. Either way log says no go and i have no idea why. Also Can't I just create a string on the php side instead of using JSON?
BOUNTY: A Thousand Internets