Skip to content Skip to sidebar Skip to footer

Npe Thrown When Trying To Find Button Id In Android Fragment

This issue has persisted repeatedly no matter how many times I redo this. According to Android Developers, the ID to an object in the View Hierarchy of a fragment is obtained durin

Solution 1:

You are using the wrong ids in your code! The buttons in your layout have the id decisionOne and decisionTwo but in your code you are using btnChoiceOne and btnChoiceTwo.

To fix it replace this:

ButtonbuttonTrue= (Button) root.findViewById(R.id.btnChoiceOne);
ButtonbuttonFalse= (Button) root.findViewById(R.id.btnChoiceTwo);

with this in your DecisionFragment:

ButtonbuttonTrue= (Button) root.findViewById(R.id.decisionOne);
ButtonbuttonFalse= (Button) root.findViewById(R.id.decisionTwo);

Solution 2:

Your button ids in code do not match with the ones in xml layout.

Solution 3:

In your xml, the id is 'decisionOne' but the code is looking for 'R.id.btnChoiceOne'

Post a Comment for "Npe Thrown When Trying To Find Button Id In Android Fragment"