0

I am trying to compile a 4KB Java game called "Left 4K Dead".. anyways, It will compile successfully with the javac G.java command, but when you go to run it using java G it spits back this error at me:

Exception in thread "main" java.lang.NoSuchMethodError: main

Anyone know how to make this work? Thanks :)

Beginning of code:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;

 public class G extends Applet implements Runnable
 {
private boolean[] k = new boolean[32767];
private int m;

public void start()
{
    enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
    new Thread(this).start();
}

public void run()
{
    BufferedImage image = new BufferedImage(240, 240, BufferedImage.TYPE_INT_RGB);
    Graphics ogr = image.getGraphics();

2 Answers 2

1

Exception in thread "main" java.lang.NoSuchMethodError: main

This exception indicates exactly what it states, there is no main method, so the program cannot start.

The issue with the Left 4k Dead code is it is an applet. It expects to be compiled and then run from a webpage, not run from command line (i.e. you can't run it with the command java). If you wish to run it from the command line, you should look into a standalone applet viewer.

Sign up to request clarification or add additional context in comments.

3 Comments

OH.. that would make sense.. in that case.. how do you run this in a web browser?
Java plugin for browsers deals with running it, specifically it runs it in its own sandbox process. The full details are a bit beyond the scope of this question, so if you are satisfied with the above answer for the current question, feel free to accept it and ask a new question about how to run it. With that said, the source code of the Left 4k Dead website may give you some help.
Ahh, ok. Did some Google research on the subject.. think I got it. Thanks :)
0

After compilation of the class, use

appletviewer <class-name>

to run it through the commandline since it is an applet.

OR ELSE

you can embed it in a browser as CodeMaker suggests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.