java.lang.NumberFormatException:无效INT:""在机器人 [英] java.lang.NumberFormatException: Invalid int: "" in android

查看:148
本文介绍了java.lang.NumberFormatException:无效INT:""在机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道是什么原因造成这个错误,我只是不知道如何处理的情况下,当用户不输入任何东西到对话框,然后点击其中解析串入一个int按钮。它不能解析一个空字符串为一个int,所以它抛出一个错误。我已经做就怎么做这方面的一些研究,但还没有发现工作满意的结果。

I already know what is causing this error, I just do not know how to handle the case when a user doesn't enter anything into the dialogue box, then hit the button which parses the string into an int. It can't parse an empty string into an int, so it throws an error. I have done some research on how to do this, but have not found a satisfactory result that works.

问题:你如何检查,看看是否该对话框中有文本,之前尝试运行的code中的其余部分。

Problem: How do you check to see if the dialogue box has text in it, before it tries to run the rest of the code.

推荐答案

有些code有助于与语法,但基本上

Some code would help with the syntax but basically

 if ("".equals(text)  // where text is the text that you get from an EditText or wherever you get it
 {    // give message to enter valid text;    }

此外,您还可以用的try / catch包围,赶上一个NumberFormatException异常然后打印相应的消息

Also, you can surround with a try/catch and catch a numberFormatException then print an appropriate message

这篇关于java.lang.NumberFormatException:无效INT:""在机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆