Results 1 to 4 of 4
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Class Class, and forName method ?

    Java Code:
    class Candy
    {
    	static
    	{
    		System.out.println("Loading Candy");
    	}
    }
    
    public class SweetShop 
    {
    	public static void main(String[] args) throws ClassNotFoundException
    	{
    		new Candy();
    		Class.forName("Candy");
    	}
    }
    When I run this code, I get:

    Loading Candy
    Exception in thread "main" java.lang.ClassNotFoundException: Candy
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at myPackage1.SweetShop.main(SweetShop.java:32)

    where I expect to get:
    Loading Candy
    Loading Candy

    What am I doing wrong here ?

  2. #2
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Class Class, and forName method ?

    Thanks, missing package in the argument.

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: Class Class, and forName method ?

    Give me the link to the question ?

    What does that mean ?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,007
    Blog Entries
    7
    Rep Power
    20

    Default Re: Class Class, and forName method ?

    Quote Originally Posted by fatabass View Post
    Give me the link to the question ?

    What does that mean ?
    Don't pay any attention to the spammer; I shredded it ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Class.forName
    By f22raptor in forum JDBC
    Replies: 5
    Last Post: 09-18-2011, 02:26 PM
  2. Class.forName()
    By jomypgeorge in forum New To Java
    Replies: 6
    Last Post: 05-02-2011, 02:56 PM
  3. Class.forName and casting
    By martinmarinov in forum Advanced Java
    Replies: 16
    Last Post: 06-09-2010, 02:42 PM
  4. about Class.forName
    By angus203 in forum New To Java
    Replies: 0
    Last Post: 11-25-2007, 04:47 AM
  5. question about Class.forName()
    By oregon in forum JDBC
    Replies: 4
    Last Post: 08-01-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •