i have login activity , signup activity , signup activity creates new user emailid , password in mysql database using jsp fine , details of user in json format . json list looks
http://192.110.8.4:8082/server/user_details_json.jsp // url below response { users: [ { user_id: "1", password: "123456", email_id: "abc.arun@gmail.com" }, { user_id: "2", password: "456789", email_id: "smart_arun@yahoo.com" } ] }
now want login in application using of above user details , have tried code , , when debugged response showing , application closes abruptly when click on login button , want above emailid , password 1 @ time , check whether matches entered text inside edittext. can suggest me how ?
private static string url = "http://192.110.8.4:8082/server/user_details_json.jsp"; edittext email_id, password; btnlogin.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // calling async task json if (email_id.gettext().tostring().equals("") && password.gettext().tostring().equals("")) { toast.maketext(getbasecontext(), "login unsuccessful", toast.length_long).show(); } else { new getuserdetails().execute(); } } }); private class getuserdetails extends asynctask<void, void, void> { string user_emailid; string user_password; hashmap<string, string> contact; @override protected void onpreexecute() { super.onpreexecute(); // showing progress dialog pdialog = new progressdialog(login.this); pdialog.settitle("contacting servers"); pdialog.setmessage("logging in ..."); pdialog.setcancelable(false); pdialog.show(); } @override protected void doinbackground(void... params) { servicehandler sh = new servicehandler(); // making request url , getting response string jsonstr = sh.makeservicecall(url, servicehandler.get); log.d("response: ", "> " + jsonstr); if (jsonstr != null) { try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node users = jsonobj.getjsonarray(tag_users); // looping through products (int = 0; < users.length(); i++) { jsonobject c = users.getjsonobject(i); user_emailid = c.getstring("email_id"); user_password = c.getstring("password"); // tmp hashmap single contact contact = new hashmap<string, string>(); // adding each child node hashmap key => value contact.put(tag_email_id, user_emailid); contact.put(tag_password, user_password); // adding contact contact list userlist.add(contact); } } catch (jsonexception e) { e.printstacktrace(); } } else { log.e("servicehandler", "couldn't data url"); } return null; } @override protected void onpostexecute(void result) { super.onpostexecute(result); if (pdialog.isshowing()) { pdialog.dismiss(); } if (email_id.gettext().tostring().equals(user_emailid) && password.gettext().tostring().equals(user_password)) { intent in = new intent(login.this, mainactivity.class); startactivity(in); } else { toast.maketext(getbasecontext(), "email-id , password not match", toast.length_long).show(); } } }
my logcat :
05-08 16:59:12.583: i/global(9037): call createsocket() return new socket. 05-08 16:59:13.133: d/response:(9037): > 05-08 16:59:13.133: d/response:(9037): 05-08 16:59:13.133: d/response:(9037): 05-08 16:59:13.133: d/response:(9037): 05-08 16:59:13.133: d/response:(9037): 05-08 16:59:13.133: d/response:(9037): {"users":[{"user_id":"1","password":"123456","email_id":"abc.arun@gmail.com"},{"user_id":"2","password":"456789","email_id":"smart_arun@yahoo.com"}]}
05-08 16:59:13.178: e/androidruntime(9037): fatal exception: asynctask #1 05-08 16:59:13.178: e/androidruntime(9037): java.lang.runtimeexception: error occured while executing doinbackground() 05-08 16:59:13.178: e/androidruntime(9037): @ android.os.asynctask$3.done(asynctask.java:299) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:352) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.futuretask.setexception(futuretask.java:219) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.futuretask.run(futuretask.java:239) 05-08 16:59:13.178: e/androidruntime(9037): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 05-08 16:59:13.178: e/androidruntime(9037): @ java.lang.thread.run(thread.java:864) 05-08 16:59:13.178: e/androidruntime(9037): caused by: java.lang.nullpointerexception 05-08 16:59:13.178: e/androidruntime(9037): @ com.example.shoppingcart.login$getuserdetails.doinbackground(login.java:219) 05-08 16:59:13.178: e/androidruntime(9037): @ com.example.shoppingcart.login$getuserdetails.doinbackground(login.java:1) 05-08 16:59:13.178: e/androidruntime(9037): @ android.os.asynctask$2.call(asynctask.java:287) 05-08 16:59:13.178: e/androidruntime(9037): @ java.util.concurrent.futuretask.run(futuretask.java:234) 05-08 16:59:13.178: e/androidruntime(9037): ... 4 more 05-08 16:59:13.943: e/windowmanager(9037): activity com.example.shoppingcart.login has leaked window com.android.internal.policy.impl.phonewindow$decorview{412ac5d8 v.e..... r......d 0,0-555,339} added here 05-08 16:59:13.943: e/windowmanager(9037): android.view.windowleaked: activity com.example.shoppingcart.login has leaked window com.android.internal.policy.impl.phonewindow$decorview{412ac5d8 v.e..... r......d 0,0-555,339} added here 05-08 16:59:13.943: e/windowmanager(9037): @ android.view.viewrootimpl.(viewrootimpl.java:458) 05-08 16:59:13.943: e/windowmanager(9037): @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:216) 05-08 16:59:13.943: e/windowmanager(9037): @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:94) 05-08 16:59:13.943: e/windowmanager(9037): @ android.app.dialog.show(dialog.java:286) 05-08 16:59:13.943: e/windowmanager(9037): @ com.example.shoppingcart.login$getuserdetails.onpreexecute(login.java:185) 05-08 16:59:13.943: e/windowmanager(9037): @ android.os.asynctask.executeonexecutor(asynctask.java:586) 05-08 16:59:13.943: e/windowmanager(9037): @ android.os.asynctask.execute(asynctask.java:534) 05-08 16:59:13.943: e/windowmanager(9037): @ com.example.shoppingcart.login$4.onclick(login.java:123) 05-08 16:59:13.943: e/windowmanager(9037): @ android.view.view.performclick(view.java:4231) 05-08 16:59:13.943: e/windowmanager(9037): @ android.view.view$performclick.run(view.java:17537) 05-08 16:59:13.943: e/windowmanager(9037): @ android.os.handler.handlecallback(handler.java:725) 05-08 16:59:13.943: e/windowmanager(9037): @ android.os.handler.dispatchmessage(handler.java:92) 05-08 16:59:13.943: e/windowmanager(9037): @ android.os.looper.loop(looper.java:158) 05-08 16:59:13.943: e/windowmanager(9037): @ android.app.activitythread.main(activitythread.java:5751) 05-08 16:59:13.943: e/windowmanager(9037): @ java.lang.reflect.method.invokenative(native method) 05-08 16:59:13.943: e/windowmanager(9037): @ java.lang.reflect.method.invoke(method.java:511) 05-08 16:59:13.943: e/windowmanager(9037): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1083) 05-08 16:59:13.943: e/windowmanager(9037): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:850) 05-08 16:59:13.943: e/windowmanager(9037): @ dalvik.system.nativestart.main(native method)
Comments
Post a Comment