Android Change textView text from another method/class -
after click on button1, layout , class gets called. want change text of textview out of class 2 results in app crash java.lang.nullpointerexception
important parts of class 1
public static textview a; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main);
[button stuff in class 1]
setcontentview(r.layout.raten); final textview = (textview) findviewbyid(r.id.a); //the textview wanna chage max = 10; easy easy = new easy(); // other class easy.e();
[now method in class 1 should change text]
public static void tx(int i) { a.settext("adsfasdf"); }
[important parts of class 2 ("easy")]
public void e(){ system.out.println("called class easy"); int max = mainactivity.max; system.out.println(max); (int i= 0; i<max; i++){ system.out.println("runde"+i); mainactivity.tx(i); }
i know, people asked such questions didn't find working solution. understood, can't access ui things outside ui thread , nullpointerexception appears, because uses "empty" public static textview a;
, not final textview = (textview) findviewbyid(r.id.a)
.
but how can make visible other methods?
sorry if post looks messed didn't konw how explain situation in better way
rather defining new local variable a, assign static.
change
final textview = (textview) findviewbyid(r.id.a); //the textview wanna chage
to
a = (textview) findviewbyid(r.id.a); //the textview wanna chage
Comments
Post a Comment