Simple compilation problem

M

mathieu

Hi there,

I am getting little rusty with java. I am trying to compile a small
project and when copy/pasting the compilation line I get:

$ javac -classpath . -d ../DICOMscope DICOMscope.java
../browser/StudyMan.java:43: package DICOMscope does not exist
import DICOMscope.*;

What do I need to do to specify that DICOMscope can be found in
DICOMscope.java (specified on the command line).

Thanks !
 
A

Andreas Leitgeb

mathieu said:
I am getting little rusty with java. I am trying to compile a small
project and when copy/pasting the compilation line I get:
$ javac -classpath . -d ../DICOMscope DICOMscope.java
./browser/StudyMan.java:43: package DICOMscope does not exist

The -d option tells javac where to put the <hierarchy> of
compiled class files.
If you had a Java source SnaFu.java that has
package com.foo.bar;
class SnaFu { ... }
in it and compiled it with
javac -d ../build any/path/to/SnaFu.java
then the resulting .class file would be written
to ../build/com/foo/bar/SnaFu.class

Now for the error:
import DICOMscope.*;

This looks like you were attempting to use classes from a *package*
named DICOMscope.
If it is indeed so, then be aware that there exist some conventions
about naming packages rather with only lowercase characters and that
there must not be a (sub-)package and a same named class in the same
location (a "Foo.java" and a package "Foo" are considered as same-named
in this context).

If you meant it as a class name, then maybe you just forgot to make
the import static (a Java 1.5 feature), or you mean
browser/StudyMan.java to just know your class DICOMscope
then remove the ".*" following it from the import line.

If all that didn't yet help, then you need to tell us the names and
the structure of all the directories involved in this case (where are
"browser", DICOMscope.java and (if such exists) the package DICOMscope),
and each relevant source file's "package" and "import" lines.
 
M

mathieu

The -d option tells javac where to put the <hierarchy> of
compiled class files.
If you had a Java source SnaFu.java that has
package com.foo.bar;
class SnaFu { ... }
in it and compiled it with
javac -d ../build any/path/to/SnaFu.java
then the resulting .class file would be written
to ../build/com/foo/bar/SnaFu.class

Now for the error:


This looks like you were attempting to use classes from a *package*
named DICOMscope.
If it is indeed so, then be aware that there exist some conventions
about naming packages rather with only lowercase characters and that
there must not be a (sub-)package and a same named class in the same
location (a "Foo.java" and a package "Foo" are considered as same-named
in this context).

If you meant it as a class name, then maybe you just forgot to make
the import static (a Java 1.5 feature), or you mean
browser/StudyMan.java to just know your class DICOMscope
then remove the ".*" following it from the import line.

If all that didn't yet help, then you need to tell us the names and
the structure of all the directories involved in this case (where are
"browser", DICOMscope.java and (if such exists) the package DICOMscope),
and each relevant source file's "package" and "import" lines.

Full src can be found here:
http://dicom.offis.de/dscope.php.en
-> ftp://dicom.offis.de/pub/dicom/offis/software/dscope/dscope351/dsgui351.zip

....
../tkgui/browser/StudyMan.java
../tkgui/DICOMscope.java
....

What is surprising is that ./tkgui/DICOMscope.java does not start with
'package DICOMscope;', but StudyMan.java uses 'import DICOMscope;'.
According to doc, this used to compile with java 1.3. I'll try the
'static' suggestion you mention later tonight.

Thanks
-M
 
A

Andreas Leitgeb

mathieu said:
Full src can be found here:
http://dicom.offis.de/dscope.php.en
-> ftp://dicom.offis.de/pub/dicom/offis/software/dscope/dscope351/dsgui351.zip
./tkgui/browser/StudyMan.java
./tkgui/DICOMscope.java
What is surprising is that ./tkgui/DICOMscope.java does not start with
'package DICOMscope;'

That is correct, because DICOMscope it is *not* a package but a class.
It is a class outside of all packages, aka in the "default package".
but StudyMan.java uses 'import DICOMscope;'.

If it uses that, it would be ok. From your previous post it looked
like it had a wrong ".*" just before the semicolon.
According to doc, this used to compile with java 1.3. I'll try the
'static' suggestion you mention later tonight.

No, forget the "static" in this particular context. It turned out
to be not relevant here. You may of course still check it out,
if you intend to do some development for Java 1.5 or later, but
there is no need to deal with it for solving this problem.

with that one line showing correctly:
import DICOMscope;
instead of (as previously posted) wrongly:
import DICOMscope.*;

I'd expect that compiler error to disappear.

If it doesn't, I won't be able to help further till about Dec 28th.
 
M

mathieu

That is correct, because DICOMscope it is *not* a package but a class.
It is a class outside of all packages, aka in the "default package".


If it uses that, it would be ok. From your previous post it looked
like it had a wrong ".*" just before the semicolon.


No, forget the "static" in this particular context. It turned out
to be not relevant here. You may of course still check it out,
if you intend to do some development for Java 1.5 or later, but
there is no need to deal with it for solving this problem.

with that one line showing correctly:
import DICOMscope;
instead of (as previously posted) wrongly:
import DICOMscope.*;

I'd expect that compiler error to disappear.

If it doesn't, I won't be able to help further till about Dec 28th.

Ok, today is the 29th :)

I removed everything, unzip from fresh zip file...still same issue:

$ javac -classpath . -d ../DICOMscope DICOMscope.java
../browser/StudyMan.java:43: '.' expected
import DICOMscope;
^
../browser/StudyMan.java:76: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
private DICOMscope parent;
^
../browser/StudyMan.java:99: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
public StudyMan(jDVInterface dvi, DICOMscope parent,Hashtable
config)
^
../about/AboutBox.java:41: '.' expected
import DICOMscope;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors


What other information do you need ?

Thanks
 
M

mathieu

Ok, today is the 29th :)

I removed everything, unzip from fresh zip file...still same issue:

$ javac -classpath . -d ../DICOMscope DICOMscope.java
./browser/StudyMan.java:43: '.' expected
import DICOMscope;
^
./browser/StudyMan.java:76: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
private DICOMscope parent;
^
./browser/StudyMan.java:99: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
public StudyMan(jDVInterface dvi, DICOMscope parent,Hashtable
config)
^
./about/AboutBox.java:41: '.' expected
import DICOMscope;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

What other information do you need ?

That was using java5, using java6 (sun-java6-jdk debian package), I am
getting the same errors message :

$ /usr/lib/jvm/java-6-sun/bin/javac -classpath . -d ../DICOMscope
DICOMscope.java
../browser/StudyMan.java:43: '.' expected
import DICOMscope;
^
../browser/StudyMan.java:43: ';' expected
import DICOMscope;
^
../browser/StudyMan.java:44: class, interface, or enum expected
import viewer.main.*;
^
../browser/StudyMan.java:76: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
private DICOMscope parent;
^
../browser/StudyMan.java:99: cannot find symbol
symbol : class DICOMscope
location: class browser.StudyMan
public StudyMan(jDVInterface dvi, DICOMscope parent,Hashtable
config)
^
../about/AboutBox.java:41: '.' expected
import DICOMscope;
^
../about/AboutBox.java:41: ';' expected
import DICOMscope;
^
../about/AboutBox.java:43: class, interface, or enum expected
import jToolkit.gui.*;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
8 errors
 
M

mathieu

That is correct, because DICOMscope it is *not* a package but a class.
It is a class outside of all packages, aka in the "default package".

After google search I found out this is deprecated behavior:

http://forums.sun.com/thread.jspa?threadID=723987&messageID=4179116

"You can no longer import classes that are not in a package. The use
of the 'default' package has always been discouraged, and Sun finally
changed the compiler to generate errors when doing so."

So what is the correct way of rewriting everything ?
 
R

RedGrittyBrick

mathieu said:
After google search I found out this is deprecated behavior:

http://forums.sun.com/thread.jspa?threadID=723987&messageID=4179116

"You can no longer import classes that are not in a package. The use
of the 'default' package has always been discouraged, and Sun finally
changed the compiler to generate errors when doing so."

So what is the correct way of rewriting everything ?

Create an appropriate package hierarchy, move the .java files to
directories with pathnames that correspond to package names, add the
appropriate "package" directives to each .java file. Add appropriate
"import" statements as needed. An IDE (e.g. Netbeans, Eclipse, others)
would probably help with this. Recompile.

I'd Google for "java package tutorial".

I'd then read Sun's java package tutorial.
http://java.sun.com/docs/books/tutorial/java/package/packages.html
 
D

dpinspira

Hi there,

  I am getting little rusty with java. I am trying to compile a small
project and when copy/pasting the compilation line I get:
Dear Friend,

Learn the software language thru masters across the world. Its quite
cost effective. Plaese go thru: www.skyquestcom.com/382824
Regards
PRASAD MD
 
A

Andreas Leitgeb

mathieu said:
After google search I found out this is deprecated behavior:
http://forums.sun.com/thread.jspa?threadID=723987&messageID=4179116

"You can no longer import classes that are not in a package. The use
of the 'default' package has always been discouraged, and Sun finally
changed the compiler to generate errors when doing so."

I just learnt something new here, too :)
So what is the correct way of rewriting everything ?

In your case, there was fortunately only one class outside of
any package, namely DICOMscope.

In the unpacked directory, where DICOMscope.java currently
resides, create a directory "snafu" and move DICOMscope.java
down into it.
Then try to recompile all, and for all the files where it
then complains about not finding DICOMscope (or printing
those strange things it did so far) you correct the line
"import DICOMscope;" to: "import snafu/DICOMscope;".

That's not a nice solution, but one that may help you
get it running as fuss-less as possible, if you do not
intend to do anything else than compile it once then
use it.

RedGrittyBrick's posting is more general, and is actually
very good advice. Mine is just more specific to your
problem and, say, more hackish.
 
A

Andreas Leitgeb

Andreas Leitgeb said:
In the unpacked directory, where DICOMscope.java currently
resides, create a directory "snafu" and move DICOMscope.java
down into it.

I forgot an important step here:
inside DICOMscope.java add a new line right at the start
with contents "package snafu;"
(or whatever name you gave that newly created directory)
 
L

Lew

Create an appropriate package hierarchy, move the .java files to
directories with pathnames that correspond to package names, add the
appropriate "package" directives to each .java file. Add appropriate
"import" statements as needed. An IDE (e.g. Netbeans, Eclipse, others)
would probably help with this. Recompile.

I'd Google for "java package tutorial".

I'd then read Sun's java package tutorial.
<http://java.sun.com/docs/books/tutorial/java/package/packages.html>

This is excellent advice, as packages are fundamental to the Java
language and should be learned as early as possible in the learning
curve.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top