I can't set main Class variable in onCreate Method
- by natrollus
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 ?