Answers for "fragment button nullpointerexception"

0

fragment button nullpointerexception

//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;
}
Posted by: Guest on April-18-2020

Code answers related to "fragment button nullpointerexception"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language