Android context NULL pointer exception
The Code context in Fragment is null.
Public class PlaceholderFragment extends Fragment {Context context = getActivity ();}
The context defined in this way is null. Of course, the actual code is not written in this way, but it means that if it is in Activity, it will not be empty, but it will be null in Fragment.
The Code context in the Activity is not null.
Public class MainActivity extends FragmentActivity {Context context = this ;}
If you obtain the context in this way, an exception is thrown.
Public class MainActivity extends FragmentActivity {Context context = getApplicationContext ();;}
The above is just a problem defined as a separate variable. if the Activity is written to the onCreate method, it is certainly possible.
Once you encounter it, let's record it together. You will also be patient once you see it.