android - cannot make a static reference to the non-static method findviewbyid(int) TextView -


i have error
cannot make static reference non-static method findviewbyid(int) type activity" in second activity

code of second activity:

public class sendquery extends main  { /////////// public method send query /////////// public static string send(string query,activity main) {     string result = "0";     inputstream = null;     string weekdayval=null;     //the query send     arraylist<namevaluepair> querysend = new arraylist<namevaluepair>();      querysend.add(new basicnamevaluepair("querysend",query));      //http post     try{         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://locali.altervista.org/php/locali.php");         httppost.setentity(new urlencodedformentity(querysend));         httpresponse response = httpclient.execute(httppost);         httpentity entity = response.getentity();         = entity.getcontent();     }catch(exception e){         log.e("log_tag", "error in http connection "+e.tostring());     }      //convert response string     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();         result=sb.tostring();         try{             jsonarray weekdetails = new jsonarray ( result); // response string             for(int index=0;index < weekdetails.length();index++)             {             jsonobject tempweekdetail = weekdetails.getjsonobject(index);             weekdayval = tempweekdetail.getstring("lunedi");// value monday             //added log can view logcat. changed above variable name             log.i("resp value","moday value "+weekdayval);             }             }catch(exception e)             {                  textview text = (textview) main.findviewbyid(r.id.textview10);                 text.settext(weekdayval);             }     }catch(exception e){         log.e("log_tag", "error converting result: "+e.tostring());     }      log.i("sendquery", result);     return result; }   } 

have first pass value main activity?
, why error?
please me! thanks

edit

i have modify code, correct? because not see writing in textview

you have declared method static.

your line of code

 textview text = (textview) findviewbyid(r.id.textview10); 

and

findviewbyid(int id) 

is activity class, requires instance of class in order use.

activity.findviewbyid(int id)

solution:

what can adding parameter method like:

public static string send(string query,activity youractivity) 

then use

 textview text = (textview) youractivity.findviewbyid(r.id.textview10); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -