I know there are a lot of topics with this error but I cannot find any solution to my problem. I am trying to implement a program which reads a file and part of the data is placed into objects, at the same time these are stuck into one array. Each line of the file is one object which I call Client or VIPClient depending on if the value is true or not. This is the error:
Exception in thread "main" java.util.InputMismatchException: For input string: "1234567890123456"
at java.util.Scanner.nextInt(Scanner.java:2166)
at java.util.Scanner.nextInt(Scanner.java:2119)
at javaapplication1.readfile.readFile(readfile.java:31)
at javaapplication1.main.main(main.java:16)
and this is the code:
public static Client[] readClients(Client[] arraycl){
//arraycl is the empty array where the objects will be placed
do{
String name=xclientes.next();
String dni=xclientes.next(); //dni is id
int ccnumber=xclientes.nextInt();//the error is here
int drivingyear=xclientes.nextInt();
boolean vip=xclientes.nextBoolean();
int vipcard=xclientes.nextInt();
for (int i=0; i<=arraycl.length ;i++){
arraycl[i] = new VIPClient(name,dni,ccnumber,drivingyear,0,null,true,vipcard);
arraycl[i]=new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]=new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]=new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]= new VIPClient(name,dni,ccnumber,drivingyear,0,null,true,vipcard);
arraycl[i]= new VIPClient(name,dni,ccnumber,drivingyear,0,null,true,vipcard);
arraycl[i]=new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]= new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]=new Client(name,dni,ccnumber,drivingyear,0,null,false);
arraycl[i]= new Client(name,dni,ccnumber,drivingyear,0,null,false);
closeFile(xclientes);
} //end for
return arraycl;
} while (xclientes.hasNext());
}//end readClientes
The 0 and null values will be set afterwards, so here is the text file:
Turing 55550000A 1234567890123456 5 true 1
Knuth 55550001B 0001000000000000 13 false
Wirth 55550010C 0010000000000000 1 false
Dijkstra 55550100D 1100000000000000 2 false
Allen 55551000E 1000000000000000 6 true 2
Curie 55550101M 0101000000000000 3 true 3
Pearl 55550110K 0110000000000000 4 false
Liskov 55551111K 1111000000000000 15 false
Pearl 55550110K 0110000000000000 8 false
Codd 55551110P 1110000000000000 7 false
The structure of the file is:
name(String) id(String) ccnumber(int) drivinyear(int) vip(boolean) vipcard (int)
I think the problem is that netbeans thinks the ccnumber is string which obviously isn't (1234567890123456), or maybe the number is too large (probably not) but I have no idea what to do. I tried to make ccnumber as a String and then parse it but it only gave me more problems. I'd be so grateful if you could give me some advice on how to solve the error.
2147483647, clearly your number is too big.intorlongforccnumberbecause you have some entries like0010000000000000. If you uselongthen0010000000000000will become same as010000000000000and10000000000000.