Search code examples
javaclasspathpackagecannot-find-symbol

User defined packages in Java


I have been editing, running, and compiling code in Notepad++ using NppExec. I have set a classpath at C:\Java. This folder contains: C:\Java\com\DOMAINNAMEWITHHELD\Classes. Inside this folder I have 3 .java files, and one .class file (Runner.java, Pirate.java, Ninja.java, and Pirate.class). I was running these files in a folder on a flash drive, and none of the three could see each other. So I moved them to my new classpath defined directory, and still cannot get anything except:

C:\Java\com\DOMAINNAMEWITHHELD\Classes\Runner.java:12: error: cannot find symbol phil.throwAStar(tim);

throwAStar() is defined in Ninja, and called in Runner.

In the three source files, I defined a package like this:

package com.DOMAINNAMEWITHHELD.Classes;

If I am in any other directory, and try:

import com.DOMAINNAMEWITHHELD.Classes.*;

I get the exact same error. What am I doing wrong?


Solution

  • So Once I cleaned up some syntax errors from troubleshooting, and trying to keep up with class, I finally got Runner, Ninja, Pirate, and now Wizard to compile, and run. In case you guys are wondering how to run a .class file contained in a package:

    Let's say the file is: C:\Java\com\DOMAINWITHHELD\classes\Runner.class

    Type this into a command prompt to run Runner:

    cd C:\Java

    java com.DOMAINWITHHELD.classes.Runner

    Now the class 'Runner' in the package 'com.DOMAINWITHHELD.classes' should execute.