Cannot resolve class in same package, async android development using eclipse -
this first android project please excuse ignorance if have missed something!
i trying change register form using json/php/mysql using async, error getting registertask cannot resolved type on line new registertask().execute();
my complete code this:
package com.app.pubcrawlorganiser; import org.json.jsonexception; import org.json.jsonobject; import com.app.pubcrawlorganiser.library.databasehandler; import com.app.pubcrawlorganiser.library.jsonparser; import com.app.pubcrawlorganiser.library.userfunctions; import android.app.activity; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.os.strictmode; import android.os.strictmode.threadpolicy; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview; @suppresswarnings("unused") public class registeractivity extends activity { button btnregister; button btnlinktologin; edittext inputfullname; edittext inputemail; edittext inputpassword; textview registererrormsg; // 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"; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.register); // importing assets buttons, text fields inputfullname = (edittext) findviewbyid(r.id.registername); inputemail = (edittext) findviewbyid(r.id.registeremail); inputpassword = (edittext) findviewbyid(r.id.registerpassword); btnregister = (button) findviewbyid(r.id.btnregister); btnlinktologin = (button) findviewbyid(r.id.btnlinktologinscreen); registererrormsg = (textview) findviewbyid(r.id.register_error); // register button click event btnregister.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { new registertask().execute(); } } ); class registertask extends asynctask<string, string, string> { protected void onpreexecute() { super.onpreexecute(); } protected string doinbackground(string... args) { string name = inputfullname.gettext().tostring(); string email = inputemail.gettext().tostring(); string password = inputpassword.gettext().tostring(); userfunctions userfunction = new userfunctions(); jsonobject json = userfunction.registeruser(name, email, password); try { if (json.getstring(key_success) != null) { registererrormsg.settext(""); string res = json.getstring(key_success); if(integer.parseint(res) == 1) { databasehandler db = new databasehandler(getapplicationcontext()); jsonobject json_user = json.getjsonobject("user"); 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)); intent dashboard = new intent(getapplicationcontext(), home.class); dashboard.addflags(intent.flag_activity_clear_top); startactivity(dashboard); finish(); } else { registererrormsg.settext("error occured in registration"); } } } catch (jsonexception e) { e.printstacktrace(); } return null; } };} protected void onpostexecute() { btnlinktologin.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent = new intent(getapplicationcontext(), welcomeactivity.class); startactivity(i); // close registration view finish(); } }); } }
why cant use class in same package?
you can't define inner class inside method! move outside oncreate()
, should work.
ps: inner classes should added @ top of outer class or @ bottom. depending on coding rules/guidelines. placing somewhere in middle pretty confusing...
Comments
Post a Comment