public class MainActivity extends FragmentActivity {
TextView textView = (TextView) findViewById(R.id.textbox);
//rest of code.........
Above code generates the following exception,
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.Activity.findViewById(Activity.java:2090)
at com.example.kuldeep.myapplication.MainActivity.<init> (MainActivity.java:24)
When I debugged this, I come to know that this code is executed even before the onCreate() method. How is this possible? and How to catch this type of exceptions?