This discussion is archived
8 Replies Latest reply: Jul 22, 2012 9:01 AM by sabre150 RSS

java applet-incompatible magic number 218774561

950754 Newbie
Currently Being Moderated
Hello, i am quite new in java and i ' ve been trying for a week to find out how to solve error incompatible magic number 218774561.

the code of my applet and my html is shown right down here:

import java.awt.*;
import javax.swing.*;
import java.applet.*;


public class appletImage extends JApplet{
MediaTracker tr;
Image img;

imagePanel panel;
public void init()
{

img = getImage(getCodeBase(), "space7.gif");
tr = new MediaTracker(this);

tr.addImage(img,0);
panel = new imagePanel(img);

setLayout(new BorderLayout());
add(panel);
}

class imagePanel extends JPanel{
private Image image;
imagePanel(Image img){super(); this.image=img;}

public void paintComponent(Graphics g) {
super.paintComponent(g);

g.drawImage(image, 0, 0, this);
}
}
}

and my html code is:

<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Image Applet</TITLE>
</HEAD>
<BODY>
<applet codebase="." code="appletImage.class" height="500" width="400">
</applet>
</BODY>
</HTML>

In my local server it works fine but in webserver(000webhost.com) NO!!!!!

The strange thing is that when i use the below code everything work in web server.

import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.applet.Applet.*;

public class appletImage extends Applet{
     Image img;
     MediaTracker tr;
     public void paint(Graphics g) {
          tr = new MediaTracker(this);
          img = getImage(getCodeBase(), "space7.gif");
          tr.addImage(img,0);
          g.drawImage(img, 0, 0, this);
     }
}

So the problem is that an error occurs when i make an instance of JPanel that draws the image...

I have checked the CAFEBABE HEX code of my .class file
i have put permissions through server

and..

i don't know what else to do!!!!!

Please help my head is going to explore!!!!!
  • 1. Re: java applet-incompatible magic number 218774561
    baftos Expert
    Currently Being Moderated
    So the problem is that an error occurs when i make an instance of JPanel that draws the image...
    Absolutely not. It does not get there at all. If you convert the reported magic number to hex, you obtain 4 bytes that correspond to the following 4 characters:
    0x0D (CarriageReturn), 0x0A (LineFeed), <, !
    This indicates that what you receive instead of the class file is most likely a HTML page containing an error.
    Point your browser directly to http:://.../appletImage.class and see what you get. If it's a prompt to download the class file, I am wrong. But if I am right, you will
    see the error in your browser.
  • 2. Re: java applet-incompatible magic number 218774561
    950754 Newbie
    Currently Being Moderated
    Wel..,l the first time i typed http://.../appletImage.class it gave me an error but the second time it prompted to download it and the third mozzilla crashed!!

    With the second applet when i typed http://.../Test.class it prompted me to download!

    So what does it mean?It is a host problem or my applet's and how do u suggest this can be solved?

    Thank you for the reply!!!
  • 3. Re: java applet-incompatible magic number 218774561
    baftos Expert
    Currently Being Moderated
    There is something fishy for sure. I don't know what it is, but if it prompted you at least once to download the class file, I think your applet is ok. When you had the error, what did it say?
    Also try to remove ".class" from your applet tag. This is usually tolerated, but not right. Just "appletImage", not "appletImage.class".
  • 4. Re: java applet-incompatible magic number 218774561
    950754 Newbie
    Currently Being Moderated
    i did what you say and i have the same problem!!

    Runtime exception
    java.lang.ClassFormatError: Incompatible magic value 218774561 in class file appletImage$imagePanel
  • 5. Re: java applet-incompatible magic number 218774561
    baftos Expert
    Currently Being Moderated
    947751 wrote:
    i did what you say and i have the same problem!!

    Runtime exception
    java.lang.ClassFormatError: Incompatible magic value 218774561 in class file appletImage$imagePanel
    Repeat what I said for appletImage$imagePanel.class. This is another .class file resulring from the compilation of imagePanel.java. Is it there on the web server?
  • 6. Re: java applet-incompatible magic number 218774561
    EJP Guru
    Currently Being Moderated
    I suggest you turn that number into hex and from there into characters. You'll probably find it is the beginning of an HTTP error page. If so, have a look at the server's access log to see what the error was and what resource was requested. If it was a class file you would be much better off using JAR files instead of directories as your codebase.
  • 7. Re: java applet-incompatible magic number 218774561
    950754 Newbie
    Currently Being Moderated
    Thank you very much buftos!! The error was that the class imagePanel was implemented inside appletImage class.When i made a separated file called imagePanel.class the error disappeared !!But why the server couldn't see imagePanel when it was implemented inside appletImage?

    Thank's again!!
  • 8. Re: java applet-incompatible magic number 218774561
    sabre150 Expert
    Currently Being Moderated
    947751 wrote:
    Thank you very much buftos!! The error was that the class imagePanel was implemented inside appletImage class.When i made a separated file called imagePanel.class the error disappeared !!But why the server couldn't see imagePanel when it was implemented inside appletImage?
    Probably because you did not copy the inner class class file to the distribution directory.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points