• 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

I'm having problems putting my own classes into packages

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic