Quantcast
Channel: User Abhishek Jain - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Abhishek Jain for Attempt to invoke virtual method 'android.content.Context android.support.v4.app.FragmentActivity.getApplicationContext()' android

$
0
0

getActivity() is null. You are probably calling this method before your activity is attached to your fragment.

From the documentation:

Caution: If you need a Context object within your Fragment, you cancall getActivity(). However, be careful to call getActivity() onlywhen the fragment is attached to an activity. When the fragment is notyet attached, or was detached during the end of its lifecycle,getActivity() will return null

Try and understand the fragment lifecycle and how it is coupled with activity lifecycle.


Viewing all articles
Browse latest Browse all 39

Latest Images

Trending Articles





Latest Images