Results 1 to 8 of 8
- 01-31-2012, 10:23 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Simple rectangle display applet doesn't work in browser
I got the code from a beginner's book called Big Java..
Here's the error I get from Firefox:
Java Code:Java Plug-in 1.6.0_22 Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM java.lang.ClassFormatError: Incompatible magic value 1768779887 in class file RectangleApplet at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.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.ClassFormatError: Incompatible magic value 1768779887 in class file RectangleApplet
Java Code:import javax.swing.JApplet; import java.awt.Rectangle; import java.awt.Graphics; import java.awt.Graphics2D; /* an applet that draws 2 rectangles*/ public class RectangleApplet extends JApplet{ public void paint(Graphics g){ /* Prepare extended graphics */ Graphics2D g2 = (Graphics2D) g; /*Construct a rectangle and draw it*/ Rectangle box = new Rectangle(15,15,60,60); g2.draw(box); /*Move rectangle 15 across and 20 down */ box.translate(15, 20); /*Draw moved rectangle */ g2.draw(box); } }
XML Code:<html> <head>Rectangles</head> <body> <applet code="RectangleApplet.class" width="300" height="400"> </applet></body> </html>
- 01-31-2012, 10:33 PM #2
Re: Simple rectangle display applet doesn't work in browser
Incompatible magic value 1768779887 in class file RectangleApplet
Create a new one and try again
That number converts to the letters: impo
Is your .class file a renamed .java file?Last edited by Norm; 01-31-2012 at 10:36 PM.
- 01-31-2012, 10:58 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Re: Simple rectangle display applet doesn't work in browser
Thanks for the response.
I think I may know why. In Eclipse, I started a 'new class' file to make this, but when I ran it it was auto-saved as a '.java' file it didnt work in the html as this (should it have?), so then I manually changed the end of it to '.class'.
I'll save it myself as .class this time and give it a go.
Just saw your edit there, yes it is! I saw that number translated on a different site as that, I was thinking it was the 'import' part? But thats there in a class file too? Sorry if I seem a bit knucleheaded about this lolLast edited by stainluss; 01-31-2012 at 11:01 PM.
- 01-31-2012, 11:56 PM #4
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
- 02-01-2012, 12:00 AM #5
Re: Simple rectangle display applet doesn't work in browser
You need to ask someone about how to use the IDE. There is a part of this forum site for IDEs.
Every time I try to create a new class in eclipse, it saves it as a .java file
-
Re: Simple rectangle display applet doesn't work in browser
The class files can be found in the bin directory, not the src directory.
- 02-01-2012, 12:34 AM #7
Member
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
-
Re: Simple rectangle display applet doesn't work in browser
But regardless, you should learn how to "Export" your project and create a jar file. The Eclipse help files can help with this.
Similar Threads
-
Why won't this rectangle display in my JFrame?
By wikemol in forum New To JavaReplies: 1Last Post: 01-07-2012, 08:14 AM -
Trying to create simple Timer, doesn't work
By Ragoune in forum New To JavaReplies: 4Last Post: 07-06-2011, 10:24 PM -
Simple SQL update doesn't work :( (Probebly easy error)
By Addez in forum New To JavaReplies: 4Last Post: 08-23-2010, 04:19 AM -
What is the different between Text format display on web browser and display on midle
By Basit781 in forum CLDC and MIDPReplies: 1Last Post: 05-31-2010, 09:46 AM -
why doesn't this short applet work?
By kim85 in forum New To JavaReplies: 1Last Post: 01-20-2008, 09:43 PM
Bookmarks