On Mon, 1 Feb 1999 16:57:16 +0100 (CET), Frank B. Brokken wrote:

>Dear listmembers,
>
>    I ran into a weird problem: I'm probably overlooking something, but
>somehow I don't see what it is.
>
>I have the following small application (using jdk 1.1.7-v1a, on a glibc based
>Linux system)
>
>public class classname
>{
>    public static void main(String args[])
>    {
>        try
>        {
>            Class
>                c = Class.forName("String");
>        }
>        catch (Exception e)
>        {
>            System.out.println(e);
>        }
>    }
>}
>
>This program generates
>
>        java.lang.ClassNotFoundException: String
>
>and I don't understand why. When I use the full class name, i.e.,
>
>                ...
>                c = Class.forName("java.lang.String");
>                ...
>
>execution proceeds flawlessly, but this is obviously not what I want. What on
>earth am I doing wrong ?

You are not doing anything wrong.  There is no "String" class unless you
wrote it.  There is a "java.lang.String" class that is part of the standard
Java classes.

Now, you may have always typed "String" rather than "java.lang.String"
but that is only because there is a default import of java.lang.*
which makes all of those classes available without the fully qualified
name.

Class.forName does not have an "import" statement since that is only
a compiler trick so that you do not have to type the full name.

You may wish to put in a bit of code where if the class is not found
you prepend the package name (or names) that you want and try again.


Michael Sinz -- Director of Research & Development, NextBus Inc.
mailto:[EMAIL PROTECTED] --------- http://www.nextbus.com
My place on the web ---> http://www.users.fast.net/~michael_sinz

Reply via email to