我正在以这种格式获取 DOB 字符串"\/Date(588657600000-0400)\/"
,我正在解析如下。
String target = custom.getDOB();
if (target == null || target == "") {
holder.item3.setText("-");
} else {
long millis = Long.parseLong(target.substring(
target.indexOf("(") + 1, target.indexOf("-")));
java.text.DateFormat df = new SimpleDateFormat("MM-dd-yyyy", Locale.ENGLISH);
holder.item3.setText(df.format(new Date(millis)));
}
我收到此错误 "04-08 22:44:09.864: E/AndroidRuntime(3837): java.lang.NumberFormatException
: Invalid long: "" 。我之前正在检查我的 String 对象是否包含null or ""
并将其设置为“-”,但我仍然我得到了这个例外。
更新:
04-08 22:59:17.423: E/AndroidRuntime(4175): java.lang.NumberFormatException: Invalid long: "" 04-08 22:59:17.423: E/AndroidRuntime(4175): 在 java.lang.Long。 invalidLong(Long.java:125) 04-08 22:59:17.423: E/AndroidRuntime(4175): at java.lang.Long.parseLong(Long.java:346) 04-08 22:59:17.423: E/ AndroidRuntime(4175):在 java.lang.Long.parseLong(Long.java:319)
我将我的 null 和空字符串文字检查更改为此,但我仍然收到此错误。
if(target == null || target.equals(""))