android - I am dealing with my web service while getting response -how to get response from server side? -


i have used post method call web service , getting error while calling web service .

logcat:

09-04 04:58:56.437: e/androidruntime(803): fatal exception: asynctask #1 09-04 04:58:56.437: e/androidruntime(803): java.lang.runtimeexception: error occure while executing doinbackground() 

the web service using class attemptlogin extends asynctask {

     /**      * before starting background thread show progress dialog      * */     boolean failure = false;      @override     protected void onpreexecute() {          string username = user.gettext().tostring();          string password = pass.gettext().tostring();         super.onpreexecute();           pdialog = new progressdialog(loginpage.this);         pdialog.setmessage("attempting login...");         pdialog.setindeterminate(false);         pdialog.setcancelable(true);         pdialog.show();      }      @override     protected string doinbackground(string... args) {         // todo auto-generated method stub          // check success tag         string username=args [0];         string password=args[1];         int success;          try {             // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();               params.add(new basicnamevaluepair("username", username));             params.add(new basicnamevaluepair("password", password));              log.d("request!", "starting");             // getting product details making http request             jsonobject json = jsonparser.makehttprequest(                    login_url, "post", params);              // check log json response             log.d("login attempt", json.tostring());              // json success tag             success = json.getint(tag_success);             if (success == 1) {                 log.d("login successful!", json.tostring());                 intent = new intent(loginpage.this, propertyapp.class);                 finish();                 startactivity(i);                 return json.getstring(tag_message);             }else{                 log.d("login failure!", json.getstring(tag_message));                 return json.getstring(tag_message);              }         } catch (jsonexception e) {             e.printstacktrace();         }          return null;                 }     /**      * after completing background task dismiss progress dialog      * **/     protected void onpostexecute(string file_url) {         // dismiss dialog once product deleted         pdialog.dismiss();         if (file_url != null){             toast.maketext(loginpage.this, file_url, toast.length_long).show();         }      }  } 

public jsonobject makehttprequest(string url, string method, list params) {

    // making http request     try {          // check request method         if(method == "post"){             // request method 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();             = httpentity.getcontent();          }else if(method == "get"){             // request method             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();             = 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 string json object     try {         jobj = new jsonobject(json);     } catch (jsonexception e) {         log.e("json parser", "error parsing data " + e.tostring());     }      // return json string     return jobj;  } 

string username = user.gettext().tostring(); move line in onpreexecute method ..u cannot handle ui in doinbackground method


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -