Below code shows null pointer exception..
public class MyFragment extends Fragment {
private String[] eArray = getActivity()
.getResources()
.getStringArray(R.array.English);
What are the other options, searching in stackoverflow did not give me success.. I am using FragmentPagerAdapter also.. which is not related to this eArray.. but it contains data for images.
getActivity() is returning null because you are using it before fragment get attached to Activity.
You need to initialize this at onCreateView
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
eArray = getActivity().getResources().getStringArray(R.array.English);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With