java - Cannot make a static reference to a non-static method -
this question has answer here:
i have in java code, when try compile code error. happens when try value of text in textview var. cannot understand error because works fine in other method.
why happens , how can fix it?
public class mainactivity extends activity { public edittext edittext; textview textview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toast.maketext(mainactivity.this, "oncreate", toast.length_long).show(); //setupmessagebutton(); edittext = (edittext) findviewbyid(r.id.edittext1); textview = (textview)findviewbyid(r.id.tvisconnected); } public void btndisplaymessage(view view){ //here works fine string missatge = edittext.gettext().tostring(); } public static string post(string url){ inputstream inputstream = null; string result = ""; //here crashes string missatge = "red"//edittext.gettext().tostring(); gives error string usuario = "foo"; ............
why?
edit: downvote question, yes, searched similar questions , i've tried static method...then don't crash content of var null , don't work @ all.
you can not access variable non static static method...
solutions:
- make edittext static
- its not logical 1 static method access variable non static, should change logic there!
greetings :)...
Comments
Post a Comment