aspose file tools*
The moose likes Beginning Java and the fly likes I'm having problems putting my own classes into packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I Watch "I New topic
Author

I'm having problems putting my own classes into packages

Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Hello. I've been putting off putting my own classes into packages for too long now.

I've read the sun tutorials and some other tutorials but for some reason i'm still having trouble and i was hoping if i just write down exactly what i've been doing someone could tell me what i'm doing wrong.

I've started reading "Devloping Games In Java " by Daivd Brackeen, and in chapter 3 he tells the reader to put some of the example classes that were in the book into their own package so we can keep using them with future examples. So this is what I've tried...


The package is called com.brackeen.javagamebook.graphics . So I created a folder named "com" and inside that folder i created a folder named "brackeen" and inside that folder created a folder named "javagamebook" and inside that folder i created a folder named "graphics". Inside the graphics folder i placed the source code for a class called "ScreenManager", (which is one of the classes i need to reuse). At the top of class I wrote the package statment and then i complied it, so the class file is in the same folder as the source.

Then in the command line i went back to the directory which all the other classes in that project are in and tried to compile the project. One of the classes in the project uses the class "SimpleScreenManger" so it has an import statement importing the package that it is in. I get this error when I try to compile...




I know i shouldn't be having as much trouble as I am but for some reason the tutorials leave me confused about exactly what i'm supposed to do when compiling classes that use classes that are in a package i have made.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
Start with small packages with one or two classes in each. Look for old threads about similar problems, like here. Note you still have to "tell us how you got on".
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18983
    
    8

Fred Blogs wrote:So I created a folder named "com"


Okay. And you created that folder inside some other folder, right? Then that other folder has to be in the classpath when you compile or use any of the classes in the com.brackeen.javagamebook.graphics package.
Neil Cartmell
Ranch Hand

Joined: Feb 13, 2010
Posts: 150
Paul Clapham wrote:
Fred Blogs wrote:So I created a folder named "com"


Okay. And you created that folder inside some other folder, right? Then that other folder has to be in the classpath when you compile or use any of the classes in the com.brackeen.javagamebook.graphics package.


Thanks that helped!. The problem was that I had not placed the folder "com" inside another folder. I was putting that folder's desitnation in the class path but i see now that the computer must have been looking for "com" inside com, so therefore couldn't find it. I think that must have been what was happening anyway.

Thanks I think I can finally start using packages now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm having problems putting my own classes into packages