extends "cannot be resolved to a type"

  • Follow


My source code is in the following locations.
http://terrorpin.net/~ben/docs/comp/lang/java/HelloDate.java
http://terrorpin.net/~ben/docs/comp/lang/java/HelloDate2.java

I am using IBM PowerPC Linux JDK 1.5 on Fedora Core 6.  HelloDate.java 
compiles fine and produces a working class.  When I try to compile 
HelloDate2.java, I get an error.  What does this error message actually 
mean?


[ben@tidbit bens]$ javac HelloDate2.java
----------
1. ERROR in HelloDate2.java (at line 1)
         class HelloDate2 extends HelloDate
                                  ^^^^^^^^^
HelloDate cannot be resolved to a type
----------
2. ERROR in HelloDate2.java (at line 5)
         printDate();
         ^^^^^^^^^
The method printDate() is undefined for the type HelloDate2
----------
2 problems (2 errors)
0
Reply Ben 3/28/2007 3:12:48 PM

"Ben Collver" <collver@peak.org> wrote in message 
news:fuSdnSa5QrNtGJfbnZ2dnUVZ_r-onZ2d@scnresearch.com...
> My source code is in the following locations.
> http://terrorpin.net/~ben/docs/comp/lang/java/HelloDate.java
> http://terrorpin.net/~ben/docs/comp/lang/java/HelloDate2.java
>
> I am using IBM PowerPC Linux JDK 1.5 on Fedora Core 6.  HelloDate.java 
> compiles fine and produces a working class.  When I try to compile 
> HelloDate2.java, I get an error.  What does this error message actually 
> mean?
>
>
> [ben@tidbit bens]$ javac HelloDate2.java
> ----------
> 1. ERROR in HelloDate2.java (at line 1)
>         class HelloDate2 extends HelloDate
>                                  ^^^^^^^^^
> HelloDate cannot be resolved to a type

    The error is saying that it cannot find this "HelloDate" class that 
you are referring to.

    Did you try compiling the files while ensuring that the current 
directory be ~ben/docs/comp/lang/java/ ? Did you ensure that "." (the 
current directory) is part of the CLASSPATH environment variable?

    - Oliver 


0
Reply Oliver 3/28/2007 3:24:28 PM


Oliver Wong wrote:
>     The error is saying that it cannot find this "HelloDate" class that 
> you are referring to.
> 
>     Did you try compiling the files while ensuring that the current 
> directory be ~ben/docs/comp/lang/java/ ? Did you ensure that "." (the 
> current directory) is part of the CLASSPATH environment variable?

Yes to the former, no to the latter.  Adding "." to the CLASSPATH 
environment variable fixes my problem on the Linux box.

My main system has no CLASSPATH environment variable.  Since it has no 
problem, I guess its Java has a built-in class path with "."

Thanks for the help,

Ben
0
Reply Ben 3/28/2007 3:54:21 PM

Oliver Wong wrote:
>>     Did you try compiling the files while ensuring that the current 
>> directory be ~ben/docs/comp/lang/java/ ? Did you ensure that "." (the 
>> current directory) is part of the CLASSPATH environment variable?

Ben Collver wrote:
> Yes to the former, no to the latter.  Adding "." to the CLASSPATH 
> environment variable fixes my problem on the Linux box.
> 
> My main system has no CLASSPATH environment variable.  Since it has no 
> problem, I guess its Java has a built-in class path with "."

Java has no "built-in class path", but your Windows box might.

Generally it is better to script (preferably with Ant) the classpath, invoking 
the -cp (-classpath) option to the 'java' command, rather than to use the 
CLASSPATH envar. CLASSPATH is global and inflexible, whereas "-cp" is 
particular and adaptable.

Also, it is a Bad Thing to use the "default package" for classes.

Better is to use a (possibly fictional) domain, for example "lewscanon.com", 
invert the top- and second-level domains and add your package name, like this:

com.lewscanon.example.package

which in most filesystems for most class loaders would correspond to the 
relative path

com/lewscanon/example/package/

in which your Foo class bytecode would appear as

com/lewscanon/example/package/Foo.class

"Relative to what?" you ask? Great question - relative to the first classpath 
element that has such a subdirectory.

These matters are covered in Sun's tutorial.

-- Lew
0
Reply Lew 3/28/2007 11:47:07 PM

Lew wrote:

> Oliver Wong wrote:
>>>     Did you try compiling the files while ensuring that the current 
>>> directory be ~ben/docs/comp/lang/java/ ? Did you ensure that "." (the 
>>> current directory) is part of the CLASSPATH environment variable?
> 
> Ben Collver wrote:
>> Yes to the former, no to the latter.  Adding "." to the CLASSPATH 
>> environment variable fixes my problem on the Linux box.
>> 
>> My main system has no CLASSPATH environment variable.  Since it has no 
>> problem, I guess its Java has a built-in class path with "."
> 
> Java has no "built-in class path", but your Windows box might.

"Linux" box...

There is a built-in class path, or at least a default which amounts to the same
thing:

   Standard Options
       -classpath classpath
              Sets  the  user class path, overriding the user class path in the
              CLASSPATH environment variable.  If neither CLASSPATH or
              -classpath is specified, the user class path consists of the 
              current directory.

-- 
Nigel Wade, System Administrator, Space Plasma Physics Group,
            University of Leicester, Leicester, LE1 7RH, UK 
E-mail :    nmw@ion.le.ac.uk 
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555
0
Reply Nigel 3/29/2007 1:08:20 PM

4 Replies
303 Views

(page loaded in 0.091 seconds)

Similiar Articles:













7/15/2012 11:02:13 PM


Reply: