Solved

Simple problem with Java packages

Posted on 2006-10-24
8
206 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 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