Check out example codes for "fragment button nullpointerexception". It will help you in understanding the concepts better.

Code Example 1

//You need to call findViewById in your root view instead:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
    View layout = inflater.inflate(R.layout.activity_warrior_self_battle_recyclerview, container, false);
    recyclerView = (RecyclerView) layout.findViewById(R.id.recycler_view);
    LinearLayoutManager layoutManager;


    //change to layout.findViewById():
    bStart = (Button) layout.findViewById(R.id.bOK); //modified
    nP1 = (EditText) layout.findViewById(R.id.nP1); //modified
    nP2 = (EditText) layout.findViewById(R.id.nP2); //modified
    bStart.setOnClickListener(this);

    layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    adapter = new WarriorBattleAdapter(getActivity());
    recyclerView.setAdapter(adapter);
    return layout;
}

Learn ReactJs, React Native from akashmittal.com