0

I've been trying to get back into programming and I've been redoing some old labs. I'm setting up Textpad 8 so I can run java applications and it works fine until I add a package statement like so:

package pkg;

public class inPkg{
    public static void main(String args[]){
            System.out.println("Hello World");
    }
}

The file's location: C:\214\pkg\inPkg.java When I compile everything is fine but when I try to run it, I get this error message:

Error: Could not find or load main class inPkg

Tool completed with exit code 1

Compile Java Tool:

Parameters: javac -classpath "$FileDir;h:\214\;c:\214\;" $File

Run Java Application Tool:

Parameters: java -classpath "$FileDir;h:\214\;c:\214\;" $BaseName

These tools are the only thing I changed in the configuration. The classpath have been written to follow the lab. instructions.

PS. Without the packages statement, the application runs perfectly.

Danny
  • 3
  • 4

2 Answers2

0

Because probably you are not using the fully qualified class name when you do the java run. use

java -classpath 'your class path' pkg.inPkg

Yohannes Gebremariam
  • 2,225
  • 3
  • 17
  • 23
  • So like, i have the file in C:\214\pkg\inPkg.java. Therefore, my parameter should be: java -classpath C:\214\pkg\inPkg? – Danny Jun 21 '18 at 18:34
0

It will compile and execute correctly with following commands

C:\214>javac.exe pkg\inPkg.java
C:\214>java.exe pkg.inPkg

Note that the file location is C:\214\pkg\inPkg.java, however you execute the commands from C:\214

Arafat Nalkhande
  • 11,078
  • 9
  • 39
  • 63