I just switched an old Android project from Eclipse to Android Studio and in that process I updated from the old support libraries version 19.0.1 to 22.2.0. After this I get some errors in my previously working code. I dowloaded all SDKs in between and checked where the error first came into play, and it seems to be in version 21.1.0 and above. I looked in the release notes for that version, but could not find anything of interest.
My error is that I am getting a NullPointerException here. Note that this method is part of the Activity, not the parent Fragment.
public synchronized void onRecipesFiltered(ArrayList<Recipe> filteredRecipes)
{
FilteredRecipesListFragment filteredRecipesListFragment = (FilteredRecipesListFragment)
getSupportFragmentManager().findFragmentById(R.id.mm_filtered_recipes_list_fragment);
// filteredRecipesListFragment becomes null
filteredRecipesListFragment.onRecipesFiltered(filteredRecipes);
}
The Fragment I am getting here is a ListFragment which is part of an XML file which is inflated at the startup of the app. It seems like this ListFragment is added to a FragmentManager inside the parent Fragment during inflation. This is probably why I get a nullpointer while getting the FragmentManager of the Activity. Thus, my question is:
How can I get the ListFragment in the Activity? Is it necessary to keep a reference to the parent Fragment to get the ListFragment through its FragmentManager? The parent Fragment is inflated when returning new MyFragment() in FragmentPagerAdapter#getItem(), nowhere else, hence it is a bit more tricky to get the proper reference in the Activity.
There is one more thing that should be noted: I saw some messages telling me I should updated to JDK 1.7, which I did (OpenJDK 1.7). I don't remember what I did, but under "External Libraries" I see <1.7> (/usr/lib/jvm/java-1.7.0-openjdk-amd64). Not sure if this matters.