• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Global declarations

  • Thread starter Thread starter Deleted User
  • Start date Start date
The specific example you gave would normally be declared in the class of some type of view or activity and not in each individual method. Then the assignment of the console variable would normally occur in the onFinishInflate() method in a view class or after you've inflated the view in an activity class, usually in the onCreate method. I'm not sure why the app would force close in any case.
 
that is because when you execute the findViewById() method, your activity doesn't have a layout yet.

try this:
PHP:
package test.tests;

public class tests extends Activity{
@Override

    Button Btest = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.Btest = (Button)this.findViewById(R.id.Button01);
}
now you execute the 'findViewById()' after you have set the layout with 'setContentView()'
 
Back
Top Bottom