1. enamul95's Avatar
    Hello Sir,
    I am new developer. I have used

    public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    static InputStream iStream = null;
    static JSONArray jarray = null;
    //static String json = "";

    // constructor
    public JSONParser() {

    }

    // function get json from url
    // by making HTTP POST or GET mehtod
    public JSONObject makeHttpRequest(String url, String method,
    List<NameValuePair> params) {

    // Making HTTP request
    try {

    // check for request method
    if(method == "POST"){
    // request method is POST
    // defaultHttpClient
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(new UrlEncodedFormEntity(params));
    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    is = httpEntity.getContent();

    }else if(method == "GET"){
    // request method is GET
    DefaultHttpClient httpClient = new DefaultHttpClient();
    String paramString = URLEncodedUtils.format(params, "utf-8");
    url += "?" + paramString;
    HttpGet httpGet = new HttpGet(url);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    HttpEntity httpEntity = httpResponse.getEntity();
    is = httpEntity.getContent();
    }

    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (ClientProtocolException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }

    try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(
    is, "iso-8859-1"), 8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
    }
    is.close();
    json = sb.toString();
    } catch (Exception e) {
    Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
    jObj = new JSONObject(json);
    } catch (JSONException e) {
    Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

    }




    }

    I am using AsyncTask.I just called it by
    json = jsonParser.makeHttpRequest(url_login, "GET", params);
    The problem is that when database or apache tomcate is not found then app has stopped giving message unfortunately app has been stopped
    06-09-2015 12:58 PM
  2. belodion's Avatar
    OP: Would you like this thread to be moved to the Android Developers forum, which I think would be a better place for it?

    Posted via the Android Central App
    06-09-2015 02:44 PM

Similar Threads

  1. Replies: 2
    Last Post: 08-27-2015, 09:20 PM
  2. How can I fix the error message Unfortunately Contacts has stopped?
    By AC Question in forum Samsung Galaxy Note 3
    Replies: 4
    Last Post: 07-29-2015, 08:59 AM
  3. Replies: 1
    Last Post: 06-12-2015, 07:49 AM
  4. g4 camera app
    By chamomiami in forum LG G4
    Replies: 7
    Last Post: 06-09-2015, 05:26 PM
  5. Removing uninstalled apps from Titanium backup
    By marios1441 in forum General News & Discussion
    Replies: 1
    Last Post: 06-09-2015, 02:07 PM
LINK TO POST COPIED TO CLIPBOARD