Results 1 to 8 of 8
  1. #1
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default ClassNotFoundException

    I was trying to embed my applet to a simple page.

    XML Code:
    <html> 
    <body> 
    <applet code="Test.class" width="700" height="750"> 
    </applet> 
    </body> 
    </html>
    My Test.class file is in the same directory as my html file. But when I run the html file, i got a bunch of errors:

    Java Code:
    Exception: java.lang.ClassNotFoundException: Test.class
    load: class Test.class not found.
    java.lang.ClassNotFoundException: Test.class
    	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: \\localhost\classes\Test\class.class (The network name cannot be found)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	... 7 more
    Exception: java.lang.ClassNotFoundException: Test.class
    Could anyone please tell me how to fix this?
    Thanks.

    P.S: I'm new, VERY new to applet. Today's the first lesson of mine on Applet at school~!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,039
    Rep Power
    20

    Default

    Isn't it simply "Test"?
    I think "Test.class" will have it looking for the "class" Class in the "Test" package.

  3. #3
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    You've probably already found the answer by now,
    but here it is again:

    Java Code:
    <html> 
    <body> 
    <applet code="Test.java" width="700" height="750"> 
    </applet> 
    </body> 
    </html>

  4. #4
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default

    Are you sure it's the ".java" file that I must put in the code = '...' part?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,039
    Rep Power
    20

    Default

    This error:
    java.io.FileNotFoundException: \\localhost\classes\Test\class.class (The network name cannot be found)

    is your problem.

    Have you tried without the .class? It's not the way it's supposed to be done, but that error implies it's the problem I mentioned above.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Following Tolls post:
    Java thought that Test.class was a package path. Ie that Test was a folder and class was the name of the .class file in the Test folder.

    Removing the .class should fix it.

  7. #7
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default

    Here is how I know

    <applet code="Test.java" width="700" height="750">

    works.

    When I read this thread, I went to one of my
    folders of java projects that use very brief html
    code to run those projects.

    I found code that is practically exact to the
    html code you wrote, except for dimensions
    and the <applet.. > line. Simply stated, I
    know empirically that
    <applet code="Test.java" width="700" height="750">
    works from the working examples in my folder.

    (note: you must have your Test.class code in that
    directory/folder to make it work, and you do not
    need the Test.java source code in there at all.)

    Why
    code = "Test.java"
    but not
    code = "Test.class"?

    I think it's because html can work with other languages.
    You could have Visual Basic code to run,
    therefore that html line would be:
    <applet code="Test.vbasic" width="700" height="750">
    or whatever extension they use to inform the html
    interpreter/compiler that Visual Basic is embedded
    within it. Still, the compiled code (Test.class) must
    exist in that directory order to be executed.
    Last edited by paul pasciak; 05-13-2010 at 11:02 PM. Reason: closed parenthesis

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    Books are wonderful things and I have many myself. However I'd always chose working code over the written word. Authors do make typos.

Similar Threads

  1. ClassNotFoundException
    By lgpublic in forum Advanced Java
    Replies: 5
    Last Post: 04-23-2010, 03:05 PM
  2. ClassNotFoundException
    By Edward in forum New To Java
    Replies: 2
    Last Post: 06-29-2009, 07:08 PM
  3. ClassNotFoundException JSP
    By TDMaster in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-27-2009, 07:41 AM
  4. ClassNotFoundException
    By Chezelle in forum Java Applets
    Replies: 5
    Last Post: 12-24-2008, 04:26 PM
  5. Replies: 0
    Last Post: 07-09-2008, 12:36 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
  •