Mike49 Mike49 - 1 year ago 70
Android Question

Can't resolve getSupportActionBar() method in fragment

I have an activity that extends ActionBarActivity and hosts a single fragment shown here:

import android.support.v7.app.ActionBarActivity;

public class CrimePagerActivity extends ActionBarActivity{

When I try to make a call to


I get an error saying it cannot be resolved. I tried passing in


which produced a NullPointerException error at runtime.

Here is the code in question.

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_crime, container, false);

if(NavUtils.getParentActivityName(getActivity()) != null) {

Answer Source

Resolved the issue by casting the return of getActivity() to ActionBarActivity: