Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Selection does not contain a main type(Selection does not contain a main type)
Selection does not contain a main type [message #781730] Sat, 21 January 2012 23:40 Go to next message
Nathaniel Trujillo is currently offline Nathaniel Trujillo
Messages: 4
Registered: January 2012
Junior Member
I typed this code the way it was in the tutorial I'm reading and it still tells me "selection does not contain a main type". Here is the code

public class Main2
{
	public static Boolean toBooleanObject(String str)
	{	
		if ("true".equalsIgnoreCase(str)) 	 { return Boolean.TRUE; }
		else if ("false".equalsIgnoreCase(str))  { return Boolean.FALSE; }
		else if ("on".equalsIgnoreCase(str))	 { return Boolean.TRUE; }
		else if ("off".equalsIgnoreCase(str))	 { return Boolean.FALSE; }
		else if ("yes".equalsIgnoreCase(str))	 { return Boolean.TRUE; }
		else if ("no".equalsIgnoreCase(str))	 { return Boolean.FALSE; }
		
		// no match
		
		return null;
			
	}
}


Thanks for any help.
Re: Selection does not contain a main type [message #781905 is a reply to message #781730] Sun, 22 January 2012 12:32 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1334
Registered: July 2009
Senior Member
On 01/21/2012 10:40 PM, Nathaniel Trujillo wrote:
> I typed this code the way it was in the tutorial I'm reading and it
> still tells me "selection does not contain a main type". Here is the code
>
> public class Main2
> {
> public static Boolean toBooleanObject(String str)
> {
> if ("true".equalsIgnoreCase(str)) { return Boolean.TRUE; }
> else if ("false".equalsIgnoreCase(str)) { return Boolean.FALSE; }
> else if ("on".equalsIgnoreCase(str)) { return Boolean.TRUE; }
> else if ("off".equalsIgnoreCase(str)) { return Boolean.FALSE; }
> else if ("yes".equalsIgnoreCase(str)) { return Boolean.TRUE; }
> else if ("no".equalsIgnoreCase(str)) { return Boolean.FALSE; }
>
> // no match
>
> return null;
>
> }
> }
>
> Thanks for any help.
The code you have does not contain a main method. In order to run a
Java class, the class has to have a public static main method that takes
a String array as its argument.

If your class doesn't have the main method, Java won't run it.
Re: Selection does not contain a main type [message #781935 is a reply to message #781905] Sun, 22 January 2012 14:36 Go to previous messageGo to next message
Nathaniel Trujillo is currently offline Nathaniel Trujillo
Messages: 4
Registered: January 2012
Junior Member
Okay, that is odd. I tried putting public static void main(String[] args){...} in there but it gave me the same message "selection does not contain a main type". Can you show me exactly what my code is supposed to look like? This is the code I tried to run

public class Main2
{
	public static void main(String[] args)
	{
		public static Boolean toBooleanObject(String str)
		{	
			if ("true".equalsIgnoreCase(str)) 	{ return Boolean.TRUE;  }
			else if ("false".equalsIgnoreCase(str)) { return Boolean.FALSE; }
			else if ("on".equalsIgnoreCase(str))	{ return Boolean.TRUE;  }
			else if ("off".equalsIgnoreCase(str))	{ return Boolean.FALSE; }
			else if ("yes".equalsIgnoreCase(str))	{ return Boolean.TRUE;  }
			else if ("no".equalsIgnoreCase(str))	{ return Boolean.FALSE; }
		
			// no match
		
			return null;
		}
	}
}
Re: Selection does not contain a main type [message #781944 is a reply to message #781935] Sun, 22 January 2012 15:09 Go to previous messageGo to next message
Nathaniel Trujillo is currently offline Nathaniel Trujillo
Messages: 4
Registered: January 2012
Junior Member
For a bit more info, it wouldn't let me post the link but if you were to take a look at the tutorial I'm reading you would notice that many of the other examples do not have a main method. Is this tutorial just outdated? If so, could you tell me in general terms how to make my code up to date? I just need something general enough to apply to each program that I write even though it may not apply to all examples. More specifically, it would be nice to have some steps that I can take to turn the code in the tutorial into the most recent version of itself. If you would need the tutorial to answer these questions then I appologize. I'll just have to wait until I make more posts. Thanks.
Re: Selection does not contain a main type [message #781946 is a reply to message #781944] Sun, 22 January 2012 15:17 Go to previous message
Nathaniel Trujillo is currently offline Nathaniel Trujillo
Messages: 4
Registered: January 2012
Junior Member
Okay, it seems like I just had to make sure that the body of the main method came before the next method. When I did that, it ran with no errors.
Previous Topic:Getting code from SVN? Help
Next Topic:Need a Java Programmer
Goto Forum:
  


Current Time: Sat Jul 26 03:20:00 EDT 2014

Powered by FUDForum. Page generated in 0.01985 seconds