I can't set main Class variable in onCreate Method
Posted
by
natrollus
on Stack Overflow
See other posts from Stack Overflow
or by natrollus
Published on 2012-10-14T15:22:36Z
Indexed on
2012/10/14
15:37 UTC
Read the original article
Hit count: 188
Main class has two variables that want to reach another class:
public class MyClassA extends Activity {
int i = 1;
Button b1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.i = 31;
this.b1 = (Button) findViewById(R.id.btn1);
~~
}
}
Second class want to call variables in mainClass object:
public class MyclassB implements OnClickListener{
MyClassA mainClass = new MyClassA();
Button btn = mainClass.b1;
int n = mainClass.i;
public void OnClick(View arg0){
Log.v("btn:",btn);
Log.v("int:",n);
}
//btn returns null;
//int returns 1;
But onCreate
method not set variables..
Why not set main class variables like this.i=31
?
© Stack Overflow or respective owner