I have a FragmentActivity which I am trying to restore the Sharedpreferences on in the onCreateView method.
My code is:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
int position = args.getInt(ARG_OBJECT);
int tabLayout = 0;
switch (position) {
case 0:
tabLayout = R.layout.layout_one;
break;
case 1:
tabLayout = R.layout.layout_two;
break;
}
View rootView = inflater.inflate(tabLayout, container, false);
//Get restore state of all checkboxes
SharedPreferences prefs = getActivity().getSharedPreferences(PREFS_NAME, 0);
String topack00value = prefs.getString("topack00", "");
CheckedTextView topack00 = (CheckedTextView) rootView.findViewById(R.id.topack_00);
switch (topack00value) {
case "yes":
topack00.setTextColor(getResources().getColor(R.color.cyan700));
topack00.setPaintFlags(topack00.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
break;
case "no":
topack00.setTextColor(getResources().getColor(R.color.black));
topack00.setPaintFlags(topack00.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
break;
default:
topack00.setTextColor(getResources().getColor(R.color.black));
topack00.setPaintFlags(topack00.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
break;
}
return rootView;
I constantly get the attempt to invoke null object resource error. The error is pointing at the topack00 checktextView but I already have it linked to the 'rootView' View.
I've had a look at a few similar cases but mine seems to be okay..Or am I completely missing something. Similar issues: Attempt to invoke virtual method
Been stuck on this for literally 5 hours. :|