android - Quick Unresolved Class Issue -
i error on line 80 (userfunction.logoutuser(getapplicationcontext());) says userfunction cannot resolved. have defined userfunction , have tried use full package name , things, can rid of error quick? (asked question future reference since happens lot) thanks!
package com.example.dashboardactivity; import libary.userfunctions; import org.json.jsonexception; import org.json.jsonobject; import android.app.activity; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; public class loginactivity extends activity { public final string tag = "loginactivity"; button btnlogin; button btnlinktoregister; edittext inputemail; edittext inputpassword; textview loginerrormsg; // json response node names private static string key_success = "success"; private static string key_error = "error"; private static string key_error_msg = "error_msg"; private static string key_uid = "uid"; private static string key_name = "name"; private static string key_email = "email"; private static string key_created_at = "created_at"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login); // importing assets buttons, text fields inputemail = (edittext) findviewbyid(r.id.loginemail); inputpassword = (edittext) findviewbyid(r.id.loginpassword); btnlogin = (button) findviewbyid(r.id.btnlogin); btnlinktoregister = (button) findviewbyid(r.id.btnlinktoregisterscreen); loginerrormsg = (textview) findviewbyid(r.id.login_error); // login button click event log.i(tag, "loginactivity login button click event" ); btnlogin.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { new asynctask<string, void, jsonobject>(){ @override protected jsonobject doinbackground(string... args) { //this run on background thread string email = args[0]; string password = args[1]; userfunctions userfunction = new userfunctions(); jsonobject json = userfunction.loginuser(email, password); return json; } @override protected void onpostexecute(jsonobject json) { //this run on ui thread if(json != null){ //... update user interface ... log.i(tag, "checking login response"); // check login response try { if (json.getstring(key_success) != null) { loginerrormsg.settext(""); string res = json.getstring(key_success); if(integer.parseint(res) == 1){ // user logged in // store user details in sqlite database libary.databasehandler db = new libary.databasehandler(getapplicationcontext()); jsonobject json_user = json.getjsonobject("user"); // clear previous data in database userfunction.logoutuser(getapplicationcontext()); db.adduser(json_user.getstring(key_name), json_user.getstring(key_email), json.getstring(key_uid), json_user.getstring(key_created_at)); // launch dashboard screen intent dashboard = new intent(getapplicationcontext(), dashboardactivity.class); // close views before launching dashboard dashboard.addflags(intent.flag_activity_clear_top); startactivity(dashboard); // close registration screen finish(); }else{ // error in login loginerrormsg.settext("incorrect username/password"); } } } catch (jsonexception e) { e.printstacktrace(); } } else{ log.e("logintask", "no login response received"); } super.onpostexecute(json); } }.execute(inputemail.gettext().tostring(), inputpassword.gettext().tostring()); } }); // link register screen log.i(tag, "loginactivity btnlinktoregister" ); btnlinktoregister.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent = new intent(getapplicationcontext(), registeractivity.class); startactivity(i); finish(); } }); } }
you've defined userfunctions userfunction = new userfunctions();
inside doinbackground
method trying access variable in onpostexecute
.
try declare userfunctions userfunction;
outside doinbackground
accessible other functions.
new asynctask<string, void, jsonobject>(){ userfunctions userfunction; @override protected jsonobject doinbackground(string... args) { //this run on background thread userfunction = new userfunctions(); } @override protected void onpostexecute(jsonobject json) { userfunction.logoutuser(getapplicationcontext()); } }
Comments
Post a Comment