java.lang.NumberFormatException: Invalid int: ""
来源:互联网 发布:销售软件 编辑:程序博客网 时间:2024/05/17 22:30
java.lang.NumberFormatException: Invalid int: “”
http://stackoverflow.com/questions/24910757/java-lang-numberformatexception-invalid-int-null
错误代码
hostText = (EditText) findViewById(R.id.host);portText = (EditText) findViewById(R.id.port);String hostName = hostText.getText().toString().trim();String portString = hostText.getText().toString().trim();int port;if(portString==null){ port=3000;}else{ port=Integer.parseInt(portString);} if (hostName == null) { hostName = "192.168.13.245";}Log.d(tag, "Input host name is: "+hostName);SocketClient client = new SocketClient();client.host = hostName;client.port = port;client.start();
正确代码
hostText = (EditText) findViewById(R.id.host);portText = (EditText) findViewById(R.id.port);String hostName = hostText.getText().toString().trim();String portString = hostText.getText().toString().trim();int port;try { port = Integer.parseInt(portString);} catch (NumberFormatException e) { port = 3000;} if (hostName == null) { hostName = "192.168.13.245"; } Log.d(tag, "Input host name is: "+hostName); SocketClient client = new SocketClient(); client.host = hostName; client.port = port; client.start();
0 0
- java.lang.NumberFormatException: Invalid int: ""
- java.lang.NumberFormatException: Invalid int: ""的解决方法
- Android报错:java.lang.NumberFormatException: Invalid int: "15112340003"
- java.lang.NumberFormatException: Invalid float
- java.lang.NumberFormatException: Invalid double: ""
- 关于String转换成int类型的java.lang.NumberFormatException: Invalid int
- Android中关于String转int遇到的java.lang.NumberFormatException: Invalid int: "5000.00"错解决办法
- 安卓异常之:java.lang.NumberFormatException: Invalid int: "1,000"
- Caused by: java.lang.NumberFormatException: Invalid double: ""
- Caused by: java.lang.NumberFormatException: Invalid double: ""
- com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Invalid double: ""
- java.lang.NumberFormatException: Invalid float: "55,4" 分析
- com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Invalid double: ""
- java.lang.NumberFormatException翻译
- Java.lang.NumberFormatException分析
- java.lang.NumberFormatException: null
- java.lang.NumberFormatException
- java.lang.NumberFormatException: null
- Java特殊字符转义(<、>、"、/、&)
- 程序员书单_sshi框架篇
- 不同内核下类型大小
- 给定一个存放整数的数组,重新排列数组使得数组左边为奇数,右边为偶数。要求:空间复杂度O(1),时间复杂度为O(n)
- HDOJ 1094 A+B for Input-Output Practice (VI)
- java.lang.NumberFormatException: Invalid int: ""
- CSS 颜色代码对应表
- PHP学习网
- HDOJ 1095 A+B for Input-Output Practice (VII)
- 监听back按键,再次点击退出应用
- Java开发中一些内置对象的总结
- 数据类型和Json格式
- 快速开发框架部分视频教程汇总
- UVa1342That Nice Euler Circuit(欧拉函数)