1

I have made my file and cannot get it to run on blogger. I have looked at a lot of information about this and cannot seem to get it to run.

Is there a problem with my code? It always comes up with class not found problem.

<applet 
    code = "Snake" 
    archive = "Snake.jar" 
    height=300 
    width=300 
    codebase="https://sites.google.com/site/zmchenryfilecabinet/filecabinet/">
</applet>

This is the output of the jar tf Snake.jar command in the command prompt:

META-INF/MANIFEST.MF
.classpath
Snake.class
Apple.class
applescaled.png
bodySprite.png
headSprite.png
apple.png
Snake.java
controlScreen.jpg
snakehead.png
endAnimation.gif
apple1.png
snakebody.png
.project

In the manifest there is an empty line after my class file and in the manifest it reads:

Manifest-Version: 1.0
Main-Class: Snake

Also my main class begins with

public class Snake extends JApplet{
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

2 Answers2

1

Console output

Some of the console output I see when I open the HTML seen below.

..
security: SSV validation: running: 1.7.0_25, requested: null, range: null
network: Created version ID: 1.7.0.25
network: Created version ID: 1.7.0.25
security: continue with running version
basic: exception: java.lang.ExceptionInInitializerError.
java.lang.RuntimeException: java.lang.ExceptionInInitializerError
    ... 
Caused by: java.lang.ExceptionInInitializerError
    at Snake.<init>(Snake.java:37)
    ... 
Caused by: java.security.AccessControlException: 
  access denied ("java.lang.RuntimePermission" "exitVM.0")
    ... 26 more
basic: Removed progress listener: sun.plugin.util.ProgressMonitorAdapter@169a11f
security: Reset deny session certificate store

Analysis

Note particularly:

at Snake.<init>(Snake.java:37)

As well as:

..AccessControlException: access denied ("java.lang.RuntimePermission" "exitVM.0")

Possibly at line 37 of Snake.java the code is doing something like:

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

That will not be allowed, even in a trusted applet. An applet might share a VM with other applets.

If my prediction is correct, try instead:

jFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Otherwise, well.. For better help sooner, post an SSCCE. Or at least the first 37 lines of Snake.java. :)

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>Applet</h1>
<applet
    code = "Snake"
    archive = "Snake.jar"
    height=300
    width=300
    codebase="https://sites.google.com/site/zmchenryfilecabinet/filecabinet/">
</applet>
</body>
</html>

Class caching

As an aside. If you are still having trouble with NCDFE (and in general with applet development).

To get around class/code caching during development, be sure to flush the class cache in the Java Console between test runs of software.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • I did as you said and you are correct that it will load the app but it still throws the RuntimeException java.lang.NoClassDefFoundError: StdDraw. – user2716701 Aug 26 '13 at 04:06
0

Have you created an Executable JAR? Try to look here.

Otherwise, if you have a ClassNotFound error, it means that some classes are missing in your JAR. Do you use some libraries in your project? If yes, make sure to extract them in your executable JAR.

Davmrtl
  • 178
  • 1
  • 1
  • 7
  • I actually finally got it to load the class file. But now I am receiving an error java.lang.NoClassDefFoundError: StdDraw but StdDraw is in my build path. Any ideas? – user2716701 Aug 26 '13 at 03:25
  • You probably forgot to put StdDraw.java in your current working directory. Try to do so and compile it. – Davmrtl Aug 26 '13 at 03:31
  • It is in included in my src folder. I used to have it as a .jar but I downloaded the .java version and included it in the src folder. I am still getting the NoClassDefFoundError though. – user2716701 Aug 26 '13 at 03:33
  • A jar file is basically a zip archive that contains *.class files. In Java, *.java files are the files that contains your source code (humain readable) while *.class files are the compiled version (computer readable) of your code in *.java files. – Davmrtl Aug 26 '13 at 03:38
  • Yeah, I have StdDraw in the build path though so shouldnt it work. It compiles fine and does not give errors. I don't understand what I am doing wrong. – user2716701 Aug 26 '13 at 03:40
  • Can you write the output of *jar tf Snake.jar* since you've added StdDraw please? – Davmrtl Aug 26 '13 at 03:42
  • The output from jar tf Snake.jar: META-INF/MANIFEST.MF Apple.class Snake.class StdDraw.class – user2716701 Aug 26 '13 at 03:44