I’m trying to input information in Java console application but I can’t seem to run it.
This is how my Java file looks like:
public class Ovning1_3
{
public static void main(String args[])
{
String name;
System.out.println("Enter your name");
name = Keyboard.readString();
System.out.println(name);
}
}
But I get the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Keyboard cannot be resolved
at Ovning1_3.main(Ovning1_3.java:9)
I have a keyboard.class file in my source folder.
I’m using Eclipse with Ubuntu.
means that the code could not be compiled.
You have to import Keyboard, something like
When you use classes from a different package (not the same package of the current class), you have to import the class. If the class is also in the same package then you need not import.
Classes are generally grouped into Packages.
How do you know the package? Go to the first like of the class. This should be something like
package xyzmeaning that the current class in thexyzpackage. The class will be in a folder calledxyzthen (This is the rule for packages: when you want to have a class in a package, sayabc.xyzthen the class should have a package declaration – the first line of the code – to be packageabc.xyzand the file should be present in a folderxyzwhich in then should be in a folderabc.