Friday, 15 May 2015

java - Could not find class 'org.json.simple.parser.JSONParser' - Android -



java - Could not find class 'org.json.simple.parser.JSONParser' - Android -

i having android activity in bundle com.blah.blah1 , java class in bundle com.blah.blah2 , trying access java class activity, throwing error

02-06 14:35:03.360: e/dalvikvm(580): not find class 'org.json.simple.parser.jsonparser', referenced method com.blah.blah2.login.login

please help resolve

i using eclipse my jars in libs folder i have added json jar build path i using jar json-simple-1.1.jar i working under android 4.0.3 eclipse java compiler version 1.6

please find below activity , java class reference

public class chat_newactivity extends activity { private string classname = "chat_newactivity"; /** asyn parameters */ private string response; /** login() parameters */ linkedhashmap<string,string> parameters ; string responsetoasync = null; urlrequestandresponse request = null; static responseparameters param = null; static string userid = null; static string securekey = null; static string status = null; static string sessionid = null; /** called when activity first created , loads main.xml content */ @override public void oncreate(bundle savedinstancestate) { log.i(classname, "creating mail service layout app..."); super.oncreate(savedinstancestate); setcontentview(r.layout.main); log.i(classname, "created"); } /** action items selected in preferences menu */ public boolean onoptionsitemselected(menuitem item) { // handle item selection switch (item.getitemid()) { case r.id.settings_menu: intent settingsactivity = new intent(getbasecontext(), chat_preferenceactivity.class); startactivity(settingsactivity); homecoming true; default: homecoming super.onoptionsitemselected(item); } } public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.menu, menu); homecoming true; } /** action calling on start chat button clicked */ public void startchat(view view) { log.i(classname, "start chat button clicked"); log.i(classname, "performing action staring chat"); log.i(classname, "performing user validation"); sharedpreferences sharedpref = preferencemanager.getdefaultsharedpreferences(getbasecontext()); chat_appinfo.pref_email = sharedpref.getstring("email",null); if (chat_appinfo.pref_email != null && chat_appinfo.pref_email.matches("[a-za-z0-9._-]+@[a-z]+.[a-z]+") && chat_appinfo.pref_email.length() > 0) { /** intent = new intent(getapplicationcontext(), appactivity.class); */ chat_appinfo.pref_firstname = sharedpref.getstring("firstname",null).tostring(); chat_appinfo.pref_lastname = sharedpref.getstring("lastname",null).tostring(); edittext getsubject = (edittext) findviewbyid(r.id.subject); chat_appinfo.pref_subject = getsubject.gettext().tostring(); log.i(classname, "first name : "+chat_appinfo.pref_firstname); log.i(classname, "last name : "+chat_appinfo.pref_lastname); log.i(classname, "last name : "+chat_appinfo.pref_email); log.i(classname, "subject : "+chat_appinfo.pref_subject); if(chat_appinfo.pref_firstname != null || chat_appinfo.pref_lastname != null || chat_appinfo.pref_subject.length() > 0) { log.i(classname, "validation completed!!!"); checknetworkconnection(); /**i.putextra(appinfo.firstname, get_firstname_from_pref); i.putextra(appinfo.lastname, get_lastname_from_pref); i.putextra(appinfo.email, get_mailid_from_pref); i.putextra(appinfo.connection_url, get_mailid_from_pref); i.putextra(appinfo.subject, subject); startactivity(i);*/ } else { toast.maketext(getapplicationcontext(), "insufficient credentials", toast.length_short).show(); } } else { toast.maketext(getapplicationcontext(), "e-mail invalid!!!", toast.length_short).show(); } } protected void checknetworkconnection() { log.i(classname, "checking network / wi-fi connection!!!"); connectivitymanager connmgr = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo networkinfo = connmgr.getactivenetworkinfo(); if (networkinfo != null && networkinfo.isconnected()) { log.i(classname, "network connection available!!!"); new asyncconnectionestablisher().execute(chat_appinfo.service_url+"loginaction"); } else { log.i(classname, "network connection not available!!!"); toast.maketext(getapplicationcontext(), "network connection not available", toast.length_short).show(); } } private class asyncconnectionestablisher extends asynctask<string, void, string> { protected string doinbackground(string... urls) { // params comes execute() call: params[0] url. log.i(classname, "performing asynchronous connection..."); string output = null; (string url : urls) { output = getoutputfromurl(url); } homecoming output; } private string getoutputfromurl(string url) { string output = null; seek { login createsessionobj = new login(); createsessionobj.login(url); output = createsessionobj.sessionid(chat_appinfo.service_url+"joinaction"); //output = login(url); } grab (exception e) { e.printstacktrace(); } homecoming output; } // onpostexecute displays results of asynctask. protected void onpostexecute(string result) { log.i(classname, "response : "+result); } } } import java.io.ioexception; import java.util.linkedhashmap; import org.json.simple.jsonobject; import org.json.simple.parser.jsonparser; import org.json.simple.parser.parseexception; import android.util.log; public class login { private string classname = "login"; linkedhashmap<string,string> parameters ; string responsetoasync = null; urlrequestandresponse request = null; string response; static responseparameters param = null; static string userid = null; static string securekey = null; static string status = null; static string sessionid = null; public void login(string url) { log.i(classname, "calling login action service url : "+url); parameters = new linkedhashmap<string,string>(); parameters.put("firstname", chat_appinfo.pref_firstname); parameters.put("lastname", chat_appinfo.pref_lastname); parameters.put("email", chat_appinfo.pref_email); parameters.put("subject", chat_appinfo.pref_subject); request = new urlrequestandresponse(); request.seturlrequestparameters(url, parameters, null); request.convertstreamtojson(); response = request.geturlresponsejson(); seek { jsonobject json = (jsonobject)new jsonparser().parse(response); param.setuserid((string) json.get("userid")); param.setsecurekey ((string) json.get("securekey")); param.setstatus((string) json.get("status")); } grab (nullpointerexception e) { system.out.println("properly set seturlrequestparameters(url, parameters, header) , convertstreamtojson() in request..."); } grab (parseexception e) { system.out.println("parse json string properly... or check servlet response in json format..."); } seek { userid = param.getuserid(); securekey = param.getsecurekey(); status = param.getstatus(); log.i(classname, "{\"userid\":\""+userid+"\",\"securekey\":\""+securekey+"\", \"status\":\""+status+"\"} "); //sessionid(chat_appinfo.service_url+"joinaction"); } grab (nullpointerexception e) { system.out.println("check parameters in response..."); } } }

are sure have included org.json.simple.parser.jsonparser class in app? cause doesn't seem on default json bundle android http://developer.android.com/reference/org/json/package-summary.html maybe should seek include these classes manually http://code.google.com/p/json-simple/source/browse/trunk/src/org/json/simple/parser/jsonparser.java?r=73

java android

No comments:

Post a Comment