Home > Blockchain >  How Can I Import java.util.Scanner into Eclipse?
How Can I Import java.util.Scanner into Eclipse?

Time:06-01

When I type "java.util." I don't even get the scanner option to come up on the list. I'm teaching myself java on youtube, and the guy had the option popped up for him. I can't even create a scanner since i'll get an error wtihout importing that java scanner. I can't do java.util.*; either since Eclipse doesn't recognize it as well.

Sorry, I'm still new to all of this. Do I need to manual download the java library packages or something? What am I suppose to do?

CodePudding user response:

Eclipse should already have JDK/JRE/SDK libraries loaded. If it is showing an error when trying to import, the most likely culprit is that you are putting it in the wrong place.

import java.util.Scanner; // It should be above the class
public class ClassName{

}

I have had a lot of issues with Eclipse in the past(specifically with suggestions popping up). If you are learning I would highly recommend BlueJ for just getting started. And then moving into IntelliJ short there after.

CodePudding user response:

Make sure you are typing in a class, when you create a new project in Eclipse it's created a module-info.java. To confirm right button in your src -> New -> Class. Now you can type the Scanner.

You can import or use directly in declaration like you're trying:

import java.util.Scanner;

    public class yourClass{
    Scanner scanner = new Scanner();
    //or
    java.util.Scanner scanner = new Scanner();
}
  • Related