java.lang.NumberFormatException: For input string: "" getting this error while using ticker for countdown

huangapple go评论70阅读模式
英文:

java.lang.NumberFormatException: For input string: "" getting this error while using ticker for countdown

问题

我想从编辑框中获取一个整数值,以便我可以在 .setCounterInSeconds(long) 上使用它,但我得到了这个错误。我的代码是:

entertime = findViewById(R.id.Txt_time);
int som = Integer.parseInt(entertime.getText().toString());

circularViewWithTimer = findViewById(R.id.circular_view);
CircularView.OptionsBuilder builderWithTimer =
        new CircularView.OptionsBuilder()
                .shouldDisplayText(true)
                .setCounterInSeconds(som)

我只想获取用户输入的时间,以便它可以从用户输入的时间开始计时。

英文:

I want a int value from edit text so I can use it on .setCounterInSeconds(long) but I'm getting this error. My code is:

 entertime = findViewById(R.id.Txt_time);
 int som = Integer.parseInt(entertime.getText().toString());




    circularViewWithTimer = findViewById(R.id.circular_view);
    CircularView.OptionsBuilder builderWithTimer =
            new CircularView.OptionsBuilder()
                    .shouldDisplayText(true)
                    .setCounterInSeconds(som)

I only want to get the time entered by the user so it start by user entered time,

答案1

得分: 0

因为您还没有在Edittext中编写任何内容,所以出现了这个错误。在从Edittext中解析值之前,您应该检查它是否为null或为空:

if (enterTime.getText().toString().isEmpty()) {
    Toast.makeText(this, "您应该输入数字", Toast.LENGTH_SHORT).show();
} else {
    进行您的工作();
}
英文:

You are getting this error because you haven't written anything in Edittext. Before parsing value from Edittext you should check if it is null or empty:

if(enterTime.getText().toString().isEmpty()){
    Toast.makeText(this,"You should enter number",Toast.LENGTG_SHORT).show()
}else{
    doYourJob()
}

huangapple
  • 本文由 发表于 2020年9月12日 02:21:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63852369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定