• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Simple problem with Java packages

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
Xavior2K3
Asked:
Xavior2K3
  • 3
  • 2
  • 2
  • +1
1 Solution
 
hoomanvCommented:
path to A should be in classpath
0
 
Xavior2K3Author Commented:
Can you give me an example?
0
 
hoomanvCommented:
Sorry it seems that named package classes cannot access default package classes.
I'll look for a workaround
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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

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

;JOOP!
0
 
hoomanvCommented:
The problem is that a named package class can not import a default package class and also classpath in this case wont help
0
 
shinobunCommented:
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
 
shinobunCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now