我正在编写一个应用程序,需要将在文本字段中输入的字符串转换为long,但是当我运行应用程序时,它强制关闭,会出现什么问题?
应用程序很简单,只需输入在文本字段中输入的值,当用户按下按钮时,它会将此值的倒计时开始为0.(回归计时器)
有代码:
private CountDownTimer countDownTimer;
private boolean timerStarted = false;
private Button buttonStart;
public TextView textView;
private final long interval = 1 * 1000;
long tempTempo2;
long minutos4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cronometro);
EditText tempTempo = (EditText) findViewById(R.id.tempo);
minutos4 = Long.parseLong(tempTempo.getText().toString());
tempTempo2 = Long.valueOf(minutos4);
buttonStart = (Button) this.findViewById(R.id.button);
buttonStart.setOnClickListener(this);
textView = (TextView) this.findViewById(R.id.textView);
countDownTimer = new CountDownTimerActivity(minutos4, interval);
textView.setText(textView.getText() + String.valueOf(minutos4/1000));
}
答案 0 :(得分:0)
对于字符串来说,重要的是长类型,即其中没有"\n" or spaces
。首先尝试修剪字符串以除去其他字符,然后转换为long。