This should be basic but I can't get it the compiler to recognize a package I created.
The file is located at c:\program files\java\com\AJF\ReadAFile.class
At top of the class, 'ReadAFile', I put this - package com.AJF;
In the class I'm building, here is the import statement - import com.AJF.*;
Environment Class Path is - ;C:\Program Files\Java\jre1.6.0_03\lib;C:\Program Files\Java\com
Error Using NetBeans says -
Compiling 1 source file to C:\JavaProjects\parse\build\classes C:\JavaProjects\parse\src\parse\Main.java:4: package com.AJF does not exist import com.AJF.*;
for starters, you don't need to import the classes when you declare your current class inside that package. All classes in AJF are available to all classes in that package. No need to import com.AJF.*;
Ok. The answer just tripped in my brain. It's the source file, it has to be in a directory with the hierarchy that matches the package name. It's working now.
Lol,I take that back. It works in Netbeans but not in a test class written in a in textpad. Weird. Compiler can't find the class. I think it is working in Netbeans because I added the folder in maybe. Still can't figure this out.
Ok, I got it to work by compiling & running the file from the command line. What's weird is in NetBeans, and JCreator, I still get the ' package doesn't exist' error at compile time. I looked around around for a solution to this but don't see anything. I have no idea why this would happen.