ClassNotFound

I am drastically trying to figure out how to use Class.forName. Even when I put
Class.forName( "java.lang.Thread" );
in the Main constructor Java returns a ClassNotFound exception. That is a class right out of the java help file for Class.forName.

Please someone can you give me a working example of using Class.forName?! Thank you!!

Comments

  • : I am drastically trying to figure out how to use Class.forName. Even when I put
    : Class.forName( "java.lang.Thread" );
    : in the Main constructor Java returns a ClassNotFound exception. That is a class right out of the java help file for Class.forName.
    :
    : Please someone can you give me a working example of using Class.forName?! Thank you!!
    :

    [code]
    Class.forName("Object");//[red]:)[/red]
    [/code]

    jk.

    just make sure that your spelling is correct. If that doesn't work, then it might be your environment variables...
    {2}rIng

  • : [code]
    : Class.forName("Object");//[red]:)[/red]
    : [/code]
    :
    : jk.
    :
    : just make sure that your spelling is correct. If that doesn't work, then it might be your environment variables...
    : {2}rIng
    :
    Haha, it seems so simple...but this code returns the same error:

    package test;
    public class Main {
    public static void main(String[] args) {

    System.out.println(Object.class.getName());
    //The class "Object" is proven to be accessable

    Class.forName("Object");//:)
    //Returns a ClassNotFound Exception
    }
    }
  • [b][red]This message was edited by Gregry2 at 2006-1-24 4:17:57[/red][/b][hr]
    :
    : : [code]
    : : Class.forName("Object");//[red]:)[/red]
    : : [/code]
    : :
    : : jk.
    : :
    : : just make sure that your spelling is correct. If that doesn't work, then it might be your environment variables...
    : : {2}rIng
    : :
    : Haha, it seems so simple...but this code returns the same error:
    : [code]
    : package test;
    : public class Main {
    : public static void main(String[] args) {
    :
    : System.out.println(Object.class.getName());
    : //The class "Object" is proven to be accessable
    :
    : Class.forName("Object");//:)
    : //Returns a ClassNotFound Exception
    : }
    : }
    [/code]

    Hmm...you know, its seems Class.forName() on my computer at least and probably on yours CAN throw a ClassNotFound exception, so it should be in a try block or be declared to be thrown. SO no exception actually occurs, you just have to prepare for one.

    Java's like that, for methods declared with a throws and a list of exceptions forces the programmer who utilizes the class to prepare for them with a try statement. For me, a C programmer, I do think it helps keep things safe, but its a little of a nuissance to me.

    Pax.
    {2}rIng



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories