Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2007

Tip: Looking for answers? Try searching our database.

extends "cannot be resolved to a type"

Thread view: 
Ben Collver - 28 Mar 2007 16:12 GMT
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)
Oliver Wong - 28 Mar 2007 16:24 GMT
> My source code is in the following locations.
> http://terrorpin.net/~ben/docs/comp/lang/java/HelloDate.java
[quoted text clipped - 11 lines]
>                                  ^^^^^^^^^
> 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
Ben Collver - 28 Mar 2007 16:54 GMT
>     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
Lew - 29 Mar 2007 00:47 GMT
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?

> 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
Nigel Wade - 29 Mar 2007 14:08 GMT
> Oliver Wong wrote:
>>>     Did you try compiling the files while ensuring that the current
[quoted text clipped - 8 lines]
>
> 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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.