0

I'm beginning to learn Java. While following a YouTube tutorial, I entered the following code:

import java.util.Scanner;


public class ageclass {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner in = new Scanner(System.in);
        int age;
        System.out.println("How older are you?");
        age=in.nextInt();
        if (age >= 18)
            System.out.println("you are old enough to drink");
        else
            System.out.println("you are not old enough");
    }
}

The code threw this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    at age.ageclass.main(ageclass.java:6)

I have looked at another thread that had an answer but I couldn't understand it. Could someone explain to me what has gone wrong?

9
  • What does the tutorial say? Go review the actual source code. Commented Feb 10, 2014 at 22:06
  • did you actually try to compile? Commented Feb 10, 2014 at 22:08
  • Could you post a link to the YouTube tutorial? And post a link to the other thread which had the answer you could not understand? Through which methods are you trying to compile and execute the code (i.e., command-line, IDE like Eclipse, etc)? Commented Feb 10, 2014 at 22:11
  • @ Sotirios Delimanolis the tutorial doesn't say anything about the error, I read the comments and no one seemed to have this problem (or well didn't post a comment about it) here is the URL youtube.com/watch?v=Cfd9DOnuF9w @Dan I am using Eclipse, I was under the impression it complies it on the fly? EDIT : here is a link to the thread stackoverflow.com/questions/21688858/… Commented Feb 10, 2014 at 22:14
  • I think in Eclipse you have to tell it to compile before running. I believe that's under the Build menu? But I remember this from over 5 years ago and it may have changed. Commented Feb 10, 2014 at 22:19

1 Answer 1

2

if you are using eclipse try to clean the project.

Project -> Clean... -> select your project -> OK

Sign up to request clarification or add additional context in comments.

3 Comments

The user appears to be a novice at Java. Can you explain to them why this might help?
I did this and it still comes back with the error, but I am intrested in why this would help (for future reference)
When you clean your project, eclipse remove the artifacts of your project. plus... if you have the auto-build turned on, eclipse will compile your project again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.