Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

843789Sep 12 2010 — edited Nov 22 2010
I am new to Java programming and I have been working out of a book trying to learn the language. I am working on a Ubuntu system using Eclipse. I get an error when I try to run this app. It is: Exception in thread "main" java.lang.NoSuchMethodError: main. I have Googled it and read different possible solutions, but none have helped. Can someone help me solve this?

Here is the code for battleshipGameTestDrive.java:_
import java.util.ArrayList;

public class battleshipGameTestDrive 
{
	
	public static void main(String[] args, ArrayList<String> locations) 	
	{
		
		int numOfGuesses = 0;
		boolean isAlive = true;
		
		GameHelper helper = new GameHelper();
		battleshipGame ship = new battleshipGame();
		
		for (int ctr = 1; ctr < 4; ctr++)
		{
			int randomNum = (int) (Math.random() * 5);		
			locations.add(Integer.toString(randomNum));
		}
			ship.setLocationCells(locations);
		
		while (isAlive == true){
			String userGuess = helper.getUserInput("Enter a number (1-7): ");
			numOfGuesses++;
			String result = ship.checkYourself(userGuess);
		
			if (result.equals("kill")){
				isAlive = false;
				System.out.println("You took " + numOfGuesses + " guesses");
			} // close result if
			
		}  //end while loop
	}// end of main

}// end of battleshipGameTestDrive class
Here is the code for the battleshipGame class.java:_
import java.util.ArrayList;

public class battleshipGame {

	private ArrayList<String> locationCells;
		
	public void setLocationCells(ArrayList<String> loc){
		locationCells = loc;
	}
	
	public String checkYourself(String userInput){
		
		String result = "miss";		
		int index = locationCells.indexOf(userInput);
		
		if (index >= 0){
			locationCells.remove(index);
			
			if (locationCells.isEmpty()){
				result = "kill";
			}else{
				result = "hit";
			}// close if
		}// closer outer if
		
		return result;
			
	}	//close method
}	//close class
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 20 2010
Added on Sep 12 2010
6 comments
963 views