Solved

Simple problem with Java packages

Posted on 2006-10-24
8
198 Views
Last Modified: 2010-03-31
Hi,

I have a class, classA (that is not in any package) that refers to another one of my classes, classB (also not in a package).
My problem is that when i put classA in a package, pack1, the complier says it cannot find the symbol classB. What am i doing wrong?

Thanks,
Michael
0
Comment
Question by:Xavior2K3
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 17797830
path to A should be in classpath
0
 
LVL 1

Author Comment

by:Xavior2K3
ID: 17797846
Can you give me an example?
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17798018
Sorry it seems that named package classes cannot access default package classes.
I'll look for a workaround
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17798308
Public classes can be accessed by any other class.
You probably forgot to make them public.

;JOOP!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:sciuriware
ID: 17798313
And if JAVA can't find a class it's because the import statement is incorrect.

;JOOP!
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 250 total points
ID: 17798340
The problem is that a named package class can not import a default package class and also classpath in this case wont help
0
 
LVL 9

Expert Comment

by:shinobun
ID: 17798816
1. Import the class:

import classB;

2. It is discouraged to make default package classes.  Just put it in a package.  (And import it!)
0
 
LVL 9

Expert Comment

by:shinobun
ID: 17798845
Unnamed packages are provided by the Java platform principally for convenience when developing small or temporary applications or when just beginning development.

http://java.sun.com/docs/books/jls/third_edition/html/packages.html#7.4.2
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which is the latest version of Apache Tomcatl 3 50
recursion example 16 111
custom annotations 9 31
couple of eclipse 5 21
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now