Exception in thread "main" java.util.NoSuchElementException: No line found
Though the code works till the print statement for a.name is executed but it throws the error as soon as the object b
is created.
I have given more inputs than required, considering that the error is demanding an input.
import java.util.*;
import java.lang.*;
import java.io.*;
class jatt{
String name;
String DOB;
String BG;
int BP;
int TeleNumber;
int DrivNumber;
String address;
void getdata(){
Scanner in =new Scanner(System.in);
name=in.nextLine();
DOB=in.nextLine();
BG=in.nextLine();
BP=in.nextInt();
TeleNumber=in.nextInt();
DrivNumber=in.nextInt();
in.nextLine();
address=in.nextLine();
}
jatt(){
getdata();
}
jatt(String name, String DOB ,String BG, int BP, int TeleNumber, int DrivNumber, String address){
this.name=name;
this.DOB=DOB;
this.BG=BG;
this.BP=BP;
this.TeleNumber=TeleNumber;
this.DrivNumber=DrivNumber;
this.address=address;
}
public static void main (String[] args) throws java.lang.Exception{
jatt a= new jatt();
System.out.println(a.name);
jatt b= new jatt();
System.out.println(b.name);
}
}
The error comes only when the second object is created, the code works fine for a single object. And I know about the problem of using in.nextLine() just after in.nextInt(). So the error is somewhere else.