X-Received: by 10.66.151.236 with SMTP id ut12mr1930164pab.22.1362125497844; Fri, 01 Mar 2013 00:11:37 -0800 (PST) X-Received: by 10.50.135.41 with SMTP id pp9mr1645357igb.2.1362125497806; Fri, 01 Mar 2013 00:11:37 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!jn4no2609850pbb.1!news-out.google.com!ov8ni25237pbb.1!nntp.google.com!jn4no2609847pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Fri, 1 Mar 2013 00:11:37 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.161.13.125; posting-account=6SonuQoAAACzSakS5dCECcJQe6ylLrzY NNTP-Posting-Host: 122.161.13.125 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9a346b17-8bba-4e06-98ef-2ecf13a51a01@googlegroups.com> Subject: Console Input Error-2 From: subhabangalore@gmail.com Injection-Date: Fri, 01 Mar 2013 08:11:37 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.programmer:22645 Dear Group, I was trying to experiment something more on scanner tried to write some mo= re code in it, I wrote the following code, //import java.io.*; import java.util.Scanner; public class AddressBook { public static void main(String[] args) { =20 System.out.println("The Name and Surname As Provided Are:"); name1(); System.out.println("\n"); address(); } =20 public static void name1(){ String name; //int age; String surname; Scanner in =3D new Scanner(System.in); =20 name =3D in.nextLine(); surname=3Din.nextLine(); in.close();=20 System.out.println("Name Is :"+name); System.out.println("Surname Is :"+surname); =20 =20 =20 } public static void address(){ String h_name; int h_no; String st_name; String city; String municipality; String district; String state; String country; int pin; Scanner in =3D new Scanner(System.in); System.out.println("Insert House Name"); h_name =3D in.nextLine(); System.out.println("Insert House No"); h_no=3Din.nextInt(); System.out.println("Insert Street Name"); st_name=3Din.nextLine(); System.out.println("Insert City Name:"); city=3Din.nextLine(); System.out.println("Insert Municipality Name"); municipality=3Din.nextLine(); System.out.println("Insert District Name"); district=3Din.nextLine(); System.out.println("Insert State Name:"); state=3Din.nextLine(); System.out.println("Insert Country Name:"); country=3Din.nextLine(); System.out.println("Insert PIN Number:"); pin=3Din.nextInt(); in.close();=20 =20 System.out.println("The House Name Is:"+h_name); System.out.println("The House Number Is:"+h_no); System.out.println("Street Name Is:"+st_name); System.out.println("The City Name Is:"+city); System.out.println("The Municipality Name Is:"+municipality); System.out.println("The District Name Is:"+district); System.out.println("The State Name Is:"+state); System.out.println("The Country Name Is:"+country); System.out.print("The Pin Code Is:"+pin); =20 } } It gave me the following error, the first method is fine but the second gave me the following error, The Name and Surname As Provided Are: Subha Banerjee Exception in thread "main" Name Is :Subha Surname Is :Banerjee Insert House Name java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at AddressBook.address(AddressBook.java:41) at AddressBook.main(AddressBook.java:9) To deal with I closed the in.close(); in first method with an idea that if = a file is called before every operation is done it should not be closed. No= w, it ran fine. Is it a silly trick just worked, or a proper way. I thought= to ask the experts in the room. Thanking You in anticipation, Regards, Subhabrata.=20