My app has been using the same code for over a years where it send an email address and a password to my JSON web services site and then retrieves the given information. I’m now trying to send some extra information for updating purposes but when I add the two extra values the app crashes.
private void doTfr() {
String result = "";
String mailAddr = " ";
String feedback = " ";
String lectName = MyLecturesActivity.LectName;
String url = "http://jobtracker.myweb.com/jsonWeb/Default.aspx";
mailAddr = "s.chase@testweb.com";
EditText fBack = (EditText) findViewById(R.id.myfeedback_feedback2);
feedback = fBack.getText().toString();
lectName = "Test Android";
url = url + "?maddr=" + mailAddr + "&pwd=FB&lect=" + "\"lectName\"&fb=\"" + feedback + "\"";
//url = url + "?maddr=" + mailAddr + &pwd=BI"; Using this url works!
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url); ****Crashes here
HttpResponse response;
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = convertStreamToString(instream);
result = result.replaceAll(""", "\"");
JSONObject json=new JSONObject(result);
JSONArray nameArray=json.names();
JSONArray valArray=json.toJSONArray(nameArray);
endif
nstream.close();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
}
}
}
When I use the commented out url it works. Can someone tell me why adding the two new values causes it to crash, could it be the size of the string?
You’d need to encode that URL to handle quotation marks.