Here is a snippet of my code:
public class ChooseNumWorkoutsDialog extends DialogFragment implements OnClickListener {
Button btnClose, btnFinished;
NumberPicker np;
public ChooseNumWorkoutsDialog() {
// Empty constructor required for DialogFragment
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_numpicker, container);
getDialog().setTitle("Number of Exercises");
btnClose = (Button) findViewById(R.id.btnClose);
btnFinished = (Button) findViewById(R.id.btnFinished);
np = (NumberPicker) findViewById(R.id.np);
//np.setMaxValue(20);
//np.setMinValue(1);
//np.setWrapSelectorWheel(false);
//btnClose.setOnClickListener(this);
//btnFinished.setOnClickListener(this);
return view;
}
The XML file does contain all referenced buttons and numberPickers. When this is run, a Null Pointer exception is found at "np.setMaxValue(20);", the only way I can get it to work is if I comment out all of the commented out parts you see.
- Is there some rule that I don't know of that states I can't set up my onclick listeners etc within a dialogfragment?
- What is the best way to solve this problem?