英文:
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()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论