• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Package Import Problem

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's sitting outside the class.
 
jorge Garcia
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Figured it out. With netbeans, you have to right click the project get to properties and add the library.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic