fragment button nullpointerexception

Solutions on MaxInterview for fragment button nullpointerexception by the best coders in the world

showing results for - "fragment button nullpointerexception"
Luisa
11 Nov 2018
1//You need to call findViewById in your root view instead:
2
3@Override
4public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
5    View layout = inflater.inflate(R.layout.activity_warrior_self_battle_recyclerview, container, false);
6    recyclerView = (RecyclerView) layout.findViewById(R.id.recycler_view);
7    LinearLayoutManager layoutManager;
8
9
10    //change to layout.findViewById():
11    bStart = (Button) layout.findViewById(R.id.bOK); //modified
12    nP1 = (EditText) layout.findViewById(R.id.nP1); //modified
13    nP2 = (EditText) layout.findViewById(R.id.nP2); //modified
14    bStart.setOnClickListener(this);
15
16    layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
17    recyclerView.setLayoutManager(layoutManager);
18    adapter = new WarriorBattleAdapter(getActivity());
19    recyclerView.setAdapter(adapter);
20    return layout;
21}