// i need to get newVal out of all these numberpickers methods separately , and i set them in to textviews , but when try to get value from the text view app crash.can you help me . how can i get numberpicker value outside it's onValuechange method?
public class MainActivity extends AppCompatActivity {
ImageButton start,pause,reset;
TextView total,mintimer,sectimer,textView6,textView7,textView8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start=(ImageButton)findViewById(R.id.start);
pause=(ImageButton)findViewById(R.id.pause);
reset=(ImageButton)findViewById(R.id.reset);
total=(TextView)findViewById(R.id.total);
mintimer=(TextView)findViewById(R.id.mintimer);
sectimer=(TextView)findViewById(R.id.sectimer);
//this is how i tried to get textview value as a string. then the app
crashes
String a=textView6.getText().toString();
NumberPicker min = (NumberPicker) findViewById(R.id.min);
NumberPicker sec = (NumberPicker) findViewById(R.id.sec);
NumberPicker brk = (NumberPicker) findViewById(R.id.brk);
min.setMinValue(1);
min.setMaxValue(20);
min.setWrapSelectorWheel(true);
min.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
textView6=(TextView)findViewById(R.id.textView6);
textView6.setText(" "+newVal);
}
});
//beep sound breake
sec.setMaxValue(60);
sec.setMinValue(0);
sec.setWrapSelectorWheel(true);
sec.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVa2, int newVal2) {
textView7=(TextView)findViewById(R.id.textView7);
textView7.setText(" "+newVal2);
}
});
//Break
brk.setMaxValue(5);
brk.setMaxValue(60);
brk.setWrapSelectorWheel(true);
brk.setOnValueChangedListener(new NumberPicker.OnValueChangeListener(){
@Override
public void onValueChange(NumberPicker picker ,int oldVal3,int newVal3){
textView8=(TextView)findViewById(R.id.textView8);
textView8.setText(" "+newVal3);
}
});
}
}
textview6 is a null object. It doesn't have instance of TextView.