DevTech101

DevTech101

For example java package mypkg1 contains the main but I am still getting the error
Error: Could not find or load main class One
Full example below.

mypkg1/One.java

package mypkg1;

import mypkg2.Res;

public class One
{
        public static void main(String[] args) {
                Two two = new Two();
                Res res = new Res();
                System.out.println(two.Two(2, 2));
                System.out.println(res.Res(4, 2));
        }
}

Two.java

package mypkg1;

public class Two 
{
    public int Two (int a, int b)
    {
        int c;
        c = a + b;
        return c;
    }
}

After compiling with javac.
pwd
/tmp/my_program
Now lets run the program, all works

java mypkg1.One
4
6

But if the same is run from /

java /tmp/prog/mypkg1.One
Error: Could not find or load main class .tmp.my_program.mypkg1.One

The solution is to simply define the CLASSPATH, or specify on the commend line

java -cp /tmp/my_program mypkg1.One
4
6
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
%d bloggers like this: