Problem running code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem running code

I always get a null exception whenever I try run code which make use of the until.Scanner class. Example: public class Names public static void main (String[] args){ Scanner input = new Scanner(System.in); String name; System.out.println("Your name: "); name = input.next(); System.out.println(name); } The above code will throw an exception when I try to run it. Can someone help out, maybe I may not be seeing the error. Thank you.

23rd Feb 2017, 4:01 PM
Emmanuel Enchill
Emmanuel Enchill - avatar
2 Answers
+ 2
You should write java.util.Scanner not until
23rd Feb 2017, 4:07 PM
Sturza Mihai-George
+ 1
not a necessity but should put input.close(); at the end as well... and not sure if miss-print but you need a "{" after the public class... public class Names{ ... }
24th Feb 2017, 4:12 AM
Michael Szczepanski
Michael Szczepanski - avatar