我想將字符串數組轉換爲整數,但整數parseInt()異常 - 發生未知源。我正在使用string.split()
和掃描儀。我使用將字符串數組轉換爲整數
Java代碼:
...{
String in = "03-02-2014 ;03-02-2014 ;LOW VALUE ;-150.65 ;11.5 ;3301.52 ;3301.52" ;
Scanner s = new Scanner(in);
String line = s.toString();
String[] parts = line.split(" ;");
//Getting First Date
String date1 = parts[0];
String[] daysDate = date1.split("-");
int dia= new Integer (Integer.parseInt(daysDate[0]));
int mes= new Integer (Integer.parseInt(daysDate[1]));
int ano= new Integer (Integer.parseInt(daysDate[2]));
//Get second date
String valueDateStri = parts[1];
String[] valueDateSplit = valueDateStri.split("-");
int vdia=Integer.parseInt(valueDateSplit[0]);
int vmes=Integer.parseInt(valueDateSplit[1]);
int vano=Integer.parseInt(valueDateSplit[2]);
//Get String Description
String desc = parts[2];
//Get Double values
double drafT = Double.parseDouble(parts[3]); //Draft
double crediT = Double.parseDouble(parts[4]); //credit
double accBalance = Double.parseDouble(parts[5]); //acountingBalance
double avbBalance = Double.parseDouble(parts[6]); //avaiableBalance
例外:
Exception in thread "main" java.lang.NumberFormatException: For input string: "java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\.][decimal separator=\,][positive prefix=][negative prefix=\Q"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
感謝您的幫助:)它的工作現在 – Renatooos