• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package Import Problem

 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.*;

Any ideas why the compiler can't see the package?

Thanks again for the help.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.*;
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's sitting outside the class.
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"com" shouldn't be part of the CLASSPATH entry; in other words, you want to include

C:\Program Files\Java

not

C:\Program Files\Java\com

The classpath entries denote directories in which the top-level-directories of class hierarchies appear, not those top-level-directories themselves.
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out. With netbeans, you have to right click the project get to properties and add the library.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic