944,196 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 12317
  • Java RSS
May 7th, 2005
0

Multiple Classes

Expand Post »
Hi,

I'm trying the Space Invaders tutorial (http://www.planetalia.com/cursos/index.jsp). I'm on part 13, which divides the code into classes. I'm using JBuilder and when I do this, I get error messages saying that the class I put in a new Java file doesn't exist. I put the java file in the same directory as the main class.

Can somebody please tell me what I'm doing wrong?

Thank you.
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
May 7th, 2005
0

Re: Multiple Classes

I can't give you much advice since I use eclipse. But check to see if the Classes are part of the same Package.

a package is eqivilent to a namespace in .NET.. Hope this helps

Paul
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
May 7th, 2005
0

Re: Multiple Classes

thanx! one more question: do all the classes have to be in the same package?
Reputation Points: 12
Solved Threads: 2
Posting Whiz
Ghost is offline Offline
352 posts
since Aug 2004
May 7th, 2005
0

Re: Multiple Classes

no. if there not you can use

import whatever.you.called.it;

example
Java Syntax (Toggle Plain Text)
  1. import java.math;

to import the java.math package (standard java package) if you wish to import say all packages in java.security you could use

Java Syntax (Toggle Plain Text)
  1. import java.security.*;

Some people think its bad coding practice to do this though. I don't find it that messy and i think the jre could manage it ok (it does do optermizations).
Reputation Points: 21
Solved Threads: 10
Junior Poster
Paul.Esson is offline Offline
181 posts
since Feb 2005
May 7th, 2005
0

Re: Multiple Classes

Compile the class you just created and JBuilder will see it. Sometimes it's not quite smart enough to see classes it created itself unless they're compiled.

As to packages: no, classes don't need to be all in the same package.
And a good thing too as otherwise you'd never be able to use any of the standard library which are all classes in packages.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Simple Command Line interface -
Next Thread in Java Forum Timeline: sorting through an array of objects





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC