0

The K.java file

package com.mypackage;
public class K{
  public static void main(String[] args) {
    System.out.println("Hello at last!");
  }
}

Now I am an Ubuntu user so I open my terminal and try to compile with the javac command.

javac K.java

and it seems to be compiled cause I get a K.class file in the same directory. The problem is when I am trying to run it with the java command.

java K

I get the following compiler error

Error: Could not find or load main class K

I also tried to run java com.mypackage.K but I am getting the same error. What am I missing? This should have been very simple right?

Mr T
  • 506
  • 2
  • 9
  • 26
  • 1
    http://stackoverflow.com/questions/7485670/error-could-not-find-or-load-main-class/29331827#29331827 – Brunaldo Oct 21 '16 at 15:18
  • So I have to set somehow the classpath variable pointing to the directory which containis the .class files? – Mr T Oct 21 '16 at 15:21
  • No, you have to set your classpath to the directory that contains the directory `com` which in turn contains the directory `mypackage` which contains the file `K.class`. – Klitos Kyriacou Oct 21 '16 at 15:37

0 Answers0