Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Some problem with "Main"?

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    22
    My Mood
    Lonely
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Some problem with "Main"?

    I'm kind of a coding newb but i managed to make 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) {}  
    	}
    }
    Its supposed to do this:
    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Some problem with "Main"?

    Exception in thread "main" java.lang.NullPointerException
    at ReactionGame.main(ReactionGame.java:14)
    There is a variable with a null value when line 14 is executed. Find the variable with the null value and then backtrack in the code to see why it is null.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. "Exception in thread "main" java.lang.NullPointerException" help?
    By redstripes in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 28th, 2014, 08:59 AM
  2. Exception in thread "main" java.lang.NullPointerException problem.......
    By Adam802 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 20th, 2012, 02:23 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM