This week's book giveaway is in the Raspberry Pi forum.
We're giving away four copies of Getting started with Java on the Raspberry Pi and have Frank DelPorte on-line!
See this thread for details.
Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Class not found exception

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to run an applet using appletviewer and getting this in cmd:

c:\Users\Joshu\Downloads\Snake game\package com.zetcode>appletviewer SnakeGame.html
load: class com.zetcode/Snake.class not found.
java.lang.ClassNotFoundException: com.zetcode.Snake.class
       at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
       at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:634)
       at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
       at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
       at sun.applet.AppletPanel.run(AppletPanel.java:378)
       at java.lang.Thread.run(Thread.java:748)


This is what is in the directory I'm calling appletviewer from:

Directory of c:\Users\Joshu\Downloads\Snake game\package com.zetcode

18/07/2017  14:21    <DIR>          .
18/07/2017  14:21    <DIR>          ..
18/07/2017  13:44               187 Board$1.class
18/07/2017  13:44             1,143 Board$TAdapter.class
18/07/2017  13:44             4,654 Board.class
18/07/2017  12:49             5,629 Board.java
18/07/2017  13:44               468 Snake$1.class
18/07/2017  13:44               782 Snake.class
18/07/2017  12:50               683 Snake.java
18/07/2017  14:24               221 SnakeGame.html
              8 File(s)         13,767 bytes
              2 Dir(s)  435,662,188,544 bytes free

This is the html file:

<!DOCTYPE html>
<html>
<head>
<title>Snake Game</title>
</head>
<body>
<APPLET code="com.zetcode/Snake." width="300" height="180"> Sorry your browser isn't able to run java applets
</APPLET>
</body>
</html>

This is the Snake.java file:




This is the board.java file:


Any ideas?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is your directory structure. It should be:

c:\Users\Joshu\Downloads\Snake game\package\com\zetcode

or probably

c:\Users\Joshu\Downloads\Snake game\com\zetcode

depending on whether you want a directory called 'package' in there or not.

BTW I can't see how you could have compiled the code as is, am I right in thinking you downloaded the class files along with the Java files?
 
Josh Diamond
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Changed the directory structure and still getting this:

C:\Users\Joshu\Downloads\Snake game\com\zetcode>appletviewer SnakeGame.html
load: class com.zetcode/Snake not found.
java.lang.ClassNotFoundException: com.zetcode.Snake
       at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
       at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:634)
       at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
       at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
       at sun.applet.AppletPanel.run(AppletPanel.java:378)
       at java.lang.Thread.run(Thread.java:748)
 
Josh Diamond
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:

BTW I can't see how you could have compiled the code as is, am I right in thinking you downloaded the class files along with the Java files?



No I compiled it normally using javac
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to run the appletviewer from the 'snake game' directory
 
Josh Diamond
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got this:

C:\Users\Joshu\Downloads\Snake game> appletviewer com/zetcode/SnakeGame.html
load: class com.zetcode/Snake not found.
java.lang.ClassNotFoundException: com.zetcode.Snake
       at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
       at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:634)
       at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
       at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
       at sun.applet.AppletPanel.run(AppletPanel.java:378)
       at java.lang.Thread.run(Thread.java:748)
 
Josh Diamond
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that what you mean by running appletviewer from the SnakeGame directory?
 
Saloon Keeper
Posts: 15124
344
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code attribute of your applet tag should read "com.zetcode.Snake.class".
 
Rancher
Posts: 5007
38
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using appletviewer and an html file?  The posted Snake class is NOT an applet.
Try using the java command instead.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well spotted Norm.
 
Josh Diamond
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for spotting my stupid mistake but when I run it it just shows a black screen which then says GameOver in the middle. Can someone else try running it and see if the same thing happens?
 
Norm Radder
Rancher
Posts: 5007
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shows a black screen which then says GameOver  


What variable(s) and conditions in the program would cause that to happen?

Have you tried debugging the code to see why it does that?  
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is you are not actually loading your ball, image and head icons and so nothing is getting displayed and after 'n' seconds the invisible ball goes out of bounds and the game finishes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic