I'm kind of a coding newb but i managed to make this:
Its supposed to do this:import java.util.Scanner; public class ReactionGame { public static void main(String[] args) { int Time = 0; String s = null; @SuppressWarnings("resource") Scanner NewScanner = new Scanner(System.in); System.out.println("Type K and press enter when STOP appears"); Delay(1000); System.out.println("STOP"); while (s.equalsIgnoreCase("k")) { String k1 = NewScanner.nextLine(); s = k1; Time ++; } System.out.println("Your time was:" + Time); } private static void Delay(int i) { try { Thread.sleep(100L); } catch (Exception e) {} } }
Say: when STOP appears enter k and enter!
then after some time
STOP
and then you must type in K+Enter
Then it will show your Score...
But it gives this error:
Type K and press enter when STOP appears
STOP
Exception in thread "main" java.lang.NullPointerException
at ReactionGame.main(ReactionGame.java:14)
I don't know what i did wrong and even eclipse doesnt give me an answer.
Kind regards,
Niels