Skip to main content


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] Sun, 22 January 2012 04:40 Go to next message
Nathaniel Trujillo is currently offline Nathaniel TrujilloFriend
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 17:32 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
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 19:36 Go to previous messageGo to next message
Nathaniel Trujillo is currently offline Nathaniel TrujilloFriend
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 20:09 Go to previous messageGo to next message
Nathaniel Trujillo is currently offline Nathaniel TrujilloFriend
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 20:17 Go to previous message
Nathaniel Trujillo is currently offline Nathaniel TrujilloFriend
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: Thu Apr 18 09:21:55 GMT 2024

Powered by FUDForum. Page generated in 0.03188 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top