java.lang.ClassFormatError: Incompatible magic value 218774561 - java

Hey everyone I am making my first applet for java today. I have been using a subdomain at a server and I don't know what to do because I am getting this really weird error.
I have my jar in the server and everything but every time I try to load the Applet this happens.
java.lang.ClassFormatError: Incompatible magic value 218774561 in class file Evolution/EvolutionApplet
Upon research it appears that an incompatible magic value means that something has been corrupted in the .jar
Here is the website http://dementedgames.site88.net/Main.html
the jars name is Evolution if you need the html code it is at the website.
Edit: The applet should be launched from Evolution.EvolutionApplet not Evolution.Evolution

The magic value of a valid Java class is 0xCAFEBABE, which is the hex value of 3405691582. This is represented by the first 4 bytes of the file. But you're getting 218774561 which in turn stands for the ASCII characters CR, LF, < and ! (the CRLF is a newline). To see it yourself, run this piece of code:
int magic = 218774561;
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(magic);
System.out.println(new String(b.array()));
This in combination with the applet being served by a website suggests that it's the start of a <!DOCTYPE> which in turn suggests that it's a HTML document.
So, the request to Evolution.jar has apparently actually returned a HTML document. You should be able to see it yourself when you change the current request URI in browser address bar to point to applet's URL (e.g. change /page.html in end of URL to /Evolution.jar). Then you'll see what the browser actually retrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document.
To fix it, just make sure that the URL in the archive attribute is correct. It's relative to the current request URL as you see in browser address bar.

The original problem seems fixed now. I could download the Jar from http://dementedgames.site88.net/Evolution.jar
Update
It seems the Evolution.Evolution class is not an applet! Running it from the command line using:
java -jar Evolution.jar
Produces a frame (with a very 'retro' look)! As such, forget this applet nonsense, and launch the frame from a link using Java Web Start.
Old Answer
OTOH it now throws a ClassNotFoundException that (after inspecting the Jar) makes me think it should be:
<html>
<head>
<title>Evolution</title>
</head>
<body bgcolor="#000000" text="#906060">
<center>
<applet code="Evolution.Evolution" archive="Evolution.jar" width="800" height="600">
</applet>
</center>
</body>
</html>
There are two changes to the code attribute worth noting.
The .class extension was removed. A minor matter, adding it is tolerated, but not correct.
The Applet removed from the class name.

BalusC above has explained it really well. In addition to that you can check this link
Thread: Incompatible magic value 218774561 error in applet
It seems that the codebase and/or the code attribute of ur applet tag need to pointed properly.

Related

Strange output in apache Tomcat?

I am facing a strange problem in apache tomcat.Suppose when I load a class in jsp file it gives me output but when i change the java file recompile changing class file the changes are not shown by apache tomcat,it shows result of previous class...for eg:
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%# page import="neww.Simpl" %>
<% Simpl demo = new Simpl();
out.println("Current date : " + demo.retur());%>
<%
out.println("Your IP addresssavxcd is " + request.getRemoteAddr());
%>
</body>
</html>
for the first time it shows correct result now if I change the Simpl.java and recompile it and run this jsp file again tomcat gives me previous result.
P.S. I am sure that the class file is modified.
I think that there is something wrong with what you are doing. In particular:
stop tomcat, delete /temp and /work subdirectories' contents, and start it up again.
I tried that already but no help!! I even tried deleting the class file but then to it gives same output.....
If you deleted the old compiled JSP class file, the work and temp directories and restarted the server .... and still saw the old behaviour, then something must be replacing the new version of the JSP source code with the old version. The only plausible explanation for that is that you are modifying the JSP in-place, and a redeploy (from the WAR?) is clobbering your tweaks. But a redeploy shouldn't happen spontaneously. You must be doing something to cause it.
The only other explanation I can think of is that you are deleting the wrong JSP class files, and it is hard to envisage how that might be happening.

How to map server response retrieved in jsp to an iFrame

I'm using struts2 framework(java/js/html/css combo) for my webapp. I am reading a text file from server and I want to write the response to an iFrame present in the same jsp.
Flow:
(1) On click of a link, I pass the relative URL of the text file to jsp.
(2) When the jsp page loads, the java code in the jsp reads the file from server.
(3) Now this response has to be written to an iFrame present in the same jsp file
Can anyone plz help me in writing such response to an iFrame?
Thanks in advance :)
[code not tested, only a demostration of the concept]
here's some very rough idea as to how to fix your code, they definitly not the best but they should be enough to help you understand the concept.
However I'd still recommend going over the whole concept and maybe come up with a more efficent way to do what you need.
if you insist on using iframe, you need to make use of 2 seperate jsp as W3C says in "Implementing HTML Frames":
Any frame that attempts to assign as its SRC a URL used by any of its ancestors is treated as if it has no SRC URL at all (basically a blank frame).
so you'll need 2 jsp, the first one is basically what you have but the the src of the iframe changed to:
<iframe scrolling="yes" width="80%" height="200" src="second.jsp?content=<%=all%>" name="imgbox" id="imgbox">
and the second one will be something like :
<html><body><%= request.getAttribute("content") %></body></html>
From the code you've shown you forced a "content update" on the iframe by using javascript. The proper/usual way to update an iframe is to provide different input parameter to the second jsp and let it update it for you.
Finally, I'd recommend using JSTL as much as possible instead of scriptlets. It is much cleaner.
What you need to do is set the src attribute of the IFRAME to the jsp url when your link is clicked. Another way to do it is doing something like this:
<iframe src="" name="iframe_a"></iframe>
<p>W3Schools.com</p>
with the correct parameters of course

File upload with Selenium WebDriver and FF24

I am facing an issue with the file upload with WebDriver, using Java, on Firefox 24.
And I can NOT use some external program like AutoIT or similar.
I have to upload a file to a section which's HTML code is:
<td>
<input type="file" name="file">
</td>
And what I was using in Eclipse is
pageObject.getTypeFileLocation().sendKeys(textFile);
pageObject.getUploadButton.click();
which does not work; also tried the first answer of this question but neither did the trick.
The test returns 'OK', but I suspected that nothing was being done so added a check to wait for 'Upload complete' text present; But the file is not uploaded, and timeouts after 20 seconds, even when the file to upload is 5KB and takes less than a second when manually uploaded.
The input=file section contains a button and a 'No File Selected' text that changes to the filepath when a file is selected manually; and this is in what I am basing my idea that the file is not being upload; because the 'No File Selected' remains until the test fails.
I tried this on Chrome and seems to be working fine, and I know that there have been some reworks about input=file in FF since release 23, but mostly pointed to CSS styling, so I don't think it's related.
Also, a question that might sound kind of stupid, but questions are questions: Doesn't the sendKeys() action need a field to input those keys? I feel that the WebDriver is trying to write the path over a button, which can't perform the action as it's only a button.
Any help will be appreciated, and thanks in advance!
Solved it!
Don't know if it works for all browsers, but at least it does on FF and Chrome:
Found out that somebody used the FILE type, so reused it and got its absolute path:
protected File *fileName* = new File("*path to file*");
private String textFile = *fileName*.getAbsolutePath();
pageObject.getInput().sendKeys(textFile);
Hope somebody else finds it useful; as it's weird to be answering my own question.

deployJava.js adds an <embed> element to head area

I have a site where I am using Java applets and have included deployJava.js load tag in the head area of the page. However when I see resulting HTML in Chrome debugger this script breaks my head content starting body immediately, so other head content appears in body tag!
You can see it live on my site http://viva-games.ru/
Also deployJava inserts an embed tag (right after body opens) so you can see an empty line in the top of page.
What I am doing wrong?
deployJava.js is a pain to integrate since it uses document.write to insert tags in the page before the document is fully loaded. Basically, it doesn't support asynchronous loading.
According to the examples from Oracle, we have to include the file somewhere in the body and call it right after the inclusion. The applet tags will be placed there.
If you want to load it asynchronously using RequireJS for instance or if you want to call it later, after the page is loaded, download the uncompressed version and replace every occurrence of:
document.write(...);
by:
document.getElementsByTagName('body')[0].insertAdjacentHTML('afterbegin', ...);
Then you can call deployJava.runApplet anywhere in your JavaScript. You can even put the applet tags in a div element somewhere in your page. The HTML code:
<body>
...
<div id="appletContainer"></div>
// The include after the div or once the page is loaded
<script type="text/javascript" src="javascript/deployJava.js"></script>
...
</body>
and the file deployJava.js:
document.getElementById('appletContainer').insertAdjacentHTML('afterbegin', ...);
Regarding the empty line, I don't have any explanation but a workaround can be found using CSS. If your applet doesn't show any GUI, you can set the appletContainer's height to 0.
NOTE: Don't hide the appletContainer using display:none, otherwise your applet won't run.

Java Applet, works in eclipse, not chrome

I have a very simple java applet, that Im using source code from the docs.oracle(http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html) site that should work, and it works in eclipse just fine, it's getting it onto the page that's the problem. The file is on a localhost server at localhost/applet/applet.html and I have the file JavaQuiz.jar in the same directory. My html file is as follows.
<hmtl>
<applet codebase="localhost/applet/"
code = 'JavaQuiz.jar'
archive = 'JavaQuiz.jar'
width = 300
height = 300 />
</html>
Is there something Im missing? Or need to change? I look forward to any help that could be given, and please try to explain it more than telling me the answer so I can learn. :D
This is what is in the java colsole
Java Plug-in 10.5.1.255
Using JRE version 1.7.0_05-b05 Java HotSpot(TM) Client VM
User home directory = C:\Users\Jihoon
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
plugin2manager.parentwindowDispose
The Chrome developer help thing doesn't show any problems. And when I click details on the applet it just says classnotfounfexception: JavaQuiz
<html>
<applet
archive="http://localhost/applet/JavaQuiz.jar"
code="JavaQuiz.class"
width = 300
height = 300 />
</html>
I think the biggest problem is not having the http:// I'm not entirely sure about the other parameters. Play around with that.
So in your case change codebase="localhost/applet/" to codebase="http://localhost/applet/"
The code attribute should point to a fully qualified class name, not to a jar.
Also you should have an eye on localhost... this means that the j.jar is located in a folder called localhost in the same directory that the html is in. Is that true? Or do you mean http://localhost:80/applet/ or /applet/
<hmtl> should be <html>
The mandatory "code" attribute (which is missing in your example) should point to the class which you intend to run (the one extending JApplet). Something like:
<html>
<applet codebase="localhost/applet/" code="yourpackage.YourApplet.class"
code = 'JavaQuiz.jar'
archive = 'JavaQuiz.jar'
width = 300
height = 300 />
</html>
http://localhost/applet/JavaQuiz.jar will not work at time of deployment.
<html>
<applet
codebase="."
archive="JavaQuiz.jar"
code="JavaQuiz"
width = 300
height = 300 >
</applet>
</html>
Since the code base points to the 'current directory' this will work for the applet while on localhost as well as deployed live.
Points, some of which have already been mentioned:
The code attribute should be the fully qualified class name of the applet class, without .class on the end.
The applet element cannot be 'self closed' - always use </applet> to close the element.
If omitted the code base defaults to the directory the HTML is in, so putting codebase="." is redundant. It should also work without it.

Categories