Java Error

JC0724

Weaksauce
Joined
Oct 11, 2008
Messages
105
So I am working on a group project to create a game for my Software engineering class. My group is using GIT and GITHUB to store/update the code.

So I created a clone from Git. I created a project in eclipse for the game. I deleted the src folder and I copied the .git folder, src folder, .gitignore text document,, nbactions.xml, nb-configuration.xml, pom.xml and README.md into the project folder from my GIT directory.

I don't think I needed all of these files but I don't think it will break the code either. I don't see any errors in the code or project.

Question, I am trying to run the game in Eclipse and I get the option to run it as Java Applet or Java Application. Either one I pick I get the error selection does not contain a main type or selection does not contain an applet.

Any ideas or help on how I fix this?
 
Java applications require a class with a main method defined. Simply point your Java Application run configuration at whatever class has 'main'. You'll need to make sure that you've told Eclipse what the source folders are first so it can compile them (Right click folder > Build Path > Use as Source Folder)
 
Question, I am trying to run the game in Eclipse and I get the option to run it as Java Applet or Java Application. Either one I pick I get the error selection does not contain a main type or selection does not contain an applet.

You want to run it as a Java Application.

The reason it's telling you it does not contain a main type is that it does not contain a main type. In order to run a Java application, you need an entry point that contains the actual program code you're running. Somewhere in your project, you need a class that has a public static main method that defines what the program actually does when you run it.

If you want your program to print "Hello World!" when you run it, you need something like this:

Code:
public class Application {
        public static void main(String[] args) {
                system.console.println("Hello World!");
        }
}

If you want your program to call the 'start' method on a 'Game' class you've defined, you need something like this:

Code:
public class Application {
        public static void main(String[] args) {
                Game game = GameFactory.getGameInstance();
                game.start();
        }
}

When you click run and pick 'Java Application' in a project that has a main method, the JVM will load all your classes and then call that method. That's how your program starts.
 
ok thanks. I actually switched to Net beans and got it running. Originally it was not working when I was running eclipse.

I came across another error, where I needed to have an instance of the database running but now everything is running smoothly. Thanks again.
 
Back
Top