Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,281 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,146 people online right now. Registration is fast and FREE... Join Now!




Game Applet Set-up Problems

 
Reply to this topicStart new topic

Game Applet Set-up Problems

Israel
22 Nov, 2008 - 01:17 AM
Post #1

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
I've been following an online tutorial and even though I have my html file and java class file in the same folder I get errors from the Java console saying the class can't be found? Here's my code and errors:

HTML:
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Java Game Applet Tutorial</title>
</head>

<body>
    <p>
        <applet code ="./FirstApplet.class" width="700" height="400">
        </applet>
    </p>
</body>
</html>


JAVA:
CODE
package FirstApplet;

import java.applet.*;
import java.awt.*;

public class FirstApplet extends Applet implements Runnable{
    
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    
    int x_pos = 10;
    int y_pos = 100;
    int radius = 20;

    // init - method is called the first time you enter the HTML site with the applet
    public void init() {
                            setBackground (Color.blue);
                        }

    // start - method is called every time you enter the HTML - site with the applet
    public void start() {
                            // define a new thread
                            Thread th = new Thread (this);
                            // start this thread
                            th.start ();
                        }

    // stop - method is called if you leave the site with the applet
    public void stop() { }

    // destroy method is called if you leave the page finally (e. g. closing browser)
    public void destroy() { }

    public void run () {
                            // lower ThreadPriority
                            Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
                    
                            // run a long while (true) this means in our case "always"
                            while (true)
                            {
                    
                                  // changing the x - position of the ball/circle
                                  x_pos ++;
                                
                                  // repaint the applet
                                  repaint();
                    
                                  try
                                  {
                                        // Stop thread for 20 milliseconds
                                        Thread.sleep (20);
                                  }
                                  catch (InterruptedException ex)
                                  {
                                        // do nothing
                                  }
                    
                                  // set ThreadPriority to maximum value
                                  Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
                    
                            }
                        }
    
    /** paint - method allows you to paint into your applet. This method is called e.g. if you move your browser window or if you call repaint() */
    public void paint (Graphics g) {
                                        // set color
                                        g.setColor (Color.red);
                                
                                        // paint a filled colored circle
                                        g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius);
                                    }
}


ERRORS:
CODE
Java Plug-in 1.6.0_10
Using JRE version 1.6.0_10 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Me-666
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
load: class ./FirstApplet.class not found.
java.lang.ClassNotFoundException: ..FirstApplet.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.net.UnknownHostException: FirstApplet
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.NetworkClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.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: ..FirstApplet.class
load: class ./FirstApplet.class not found.
java.lang.ClassNotFoundException: ..FirstApplet.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.net.UnknownHostException: FirstApplet
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.NetworkClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.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: ..FirstApplet.class


User is offlineProfile CardPM
+Quote Post


Martyr2
RE: Game Applet Set-up Problems
22 Nov, 2008 - 01:41 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 6,656



Thanked: 613 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well first get rid of the package FirstApplet from the top of the java file. Recompile. Second, if the file is local to the applet, remove the "./" from the front in the HTML file.

It should now work fine. smile.gif
User is offlineProfile CardPM
+Quote Post

Israel
RE: Game Applet Set-up Problems
22 Nov, 2008 - 02:04 AM
Post #3

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
Ok, I did that but I still get some errors. However there seems to be less of them.

CODE
java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    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)
Exception: java.lang.NoClassDefFoundError: FirstApplet (wrong name: FirstApplet/FirstApplet)
load: class ./FirstApplet.class not found.
java.lang.ClassNotFoundException: ..FirstApplet.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.net.UnknownHostException: FirstApplet
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.NetworkClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.ftp.FtpClient.openServer(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.ftp.FtpURLConnection.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: ..FirstApplet.class

User is offlineProfile CardPM
+Quote Post

pbl
RE: Game Applet Set-up Problems
22 Nov, 2008 - 10:58 AM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 6,951



Thanked: 673 times
Dream Kudos: 200
My Contributions
As Martyr suggested you shouldn't use a package because then it is relative to your root

I did what he suggested:

CODE

    <p>
        <applet code ="FirstApplet.class" width="700" height="400">
        </applet>
    </p>

I suspected, based on the error message, that you didn't do the previous part
and then in your code:

CODE

// package FirstApplet;    commented out

import java.applet.*;


And this is what I get (with the red ball flickering)

This post has been edited by pbl: 22 Nov, 2008 - 11:00 AM


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

Israel
RE: Game Applet Set-up Problems
22 Nov, 2008 - 10:58 AM
Post #5

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
Googled some errors and saw apparently and the whole classpath can help. Now I'm just down to these errors:

CODE
load: class C:\Documents and Settings\Me-666\workspace\FirstApp\bin\FirstApplet.class not found.
java.lang.ClassNotFoundException: C:.Documents and Settings.Me-666.workspace.FirstApp.bin.FirstApplet.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.net.MalformedURLException: unknown protocol: c
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 7 more
Exception: java.lang.ClassNotFoundException: C:.Documents and Settings.Me-666.workspace.FirstApp.bin.FirstApplet.class


QUOTE
As Martyr suggested you shouldn't use a package because then it is relative to your root


I did that after he suggested it. Got less errors, but their still there...

This post has been edited by Israel: 22 Nov, 2008 - 11:03 AM
User is offlineProfile CardPM
+Quote Post

Israel
RE: Game Applet Set-up Problems
22 Nov, 2008 - 11:23 AM
Post #6

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
Got it! Apparently Eclipse wouldn't let me save/compile that class file without errors when I took away the package at the top. I didn't notice this when I saved it before. But I re-wrote it in its own class file without linking it to a package it works! Thanks for keeping me going wink2.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Game Applet Set-up Problems
22 Nov, 2008 - 12:20 PM
Post #7

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 6,656



Thanked: 613 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Damn that Eclipse! wink2.gif

Glad things are working for you now. Thanks to pbl for checking that out and the backup. icon_up.gif
User is offlineProfile CardPM
+Quote Post

pbl
RE: Game Applet Set-up Problems
22 Nov, 2008 - 12:25 PM
Post #8

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 6,951



Thanked: 673 times
Dream Kudos: 200
My Contributions
QUOTE(Martyr2 @ 22 Nov, 2008 - 12:20 PM) *

Damn that Eclipse! wink2.gif

Glad things are working for you now. Thanks to pbl for checking that out and the backup. icon_up.gif

Having removing the package statement in Eclipse should have generated an error as the class became in the default package but was still in Eclipse "/FirstApplet" sub directory.

Probably didn't realized there was an error
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:08PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month