We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Simple problem with Java packages

Xavior2K3
Xavior2K3 asked
on
Medium Priority
248 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
Comment
Watch Question

Top Expert 2006

Commented:
path to A should be in classpath

Author

Commented:
Can you give me an example?
Top Expert 2006

Commented:
Sorry it seems that named package classes cannot access default package classes.
I'll look for a workaround
Public classes can be accessed by any other class.
You probably forgot to make them public.

;JOOP!
And if JAVA can't find a class it's because the import statement is incorrect.

;JOOP!
Top Expert 2006
Commented:
The problem is that a named package class can not import a default package class and also classpath in this case wont help

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
1. Import the class:

import classB;

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

Commented:
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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.