Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: Application not running. "No main methods, applets, or MIDlets found in file."

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Application not running. "No main methods, applets, or MIDlets found in file."

    I'm currently working on an assignment for my Java class with the following instructions:

    Your application will consist of one class, PetAdvice.
    Use an input dialog box to request the type of dwelling the program user lives in.

    Edit the value entered into the input dialog box. The value must be A, a, H, h, D, or d. Display a message dialog box indicating an invalid value was entered if A, a, H, h, D, or d was not entered. Your message dialog must look like Figure 2 below. Stop the application after displaying the error message dialog if invalid data was entered. Continue processing if a valid value was entered.



    The program logic to display the input dialog box and edit the input for type of dwelling must be in its own method and separate from main().
    Use an input dialog box to request the number of hours the program user is at home during the day. Your input dialog must look like Figure 3 below.


    Edit the value entered into the input dialog box. The value must be A, a, B, b, C, c, D, d, E or e. Display a message dialog box indicating an invalid value was entered if A, a, B, b, C, c, D, d, E or e was not entered. Your message dialog must look like Figure 4 below. Stop the application after displaying the error message dialog if invalid data was entered. Continue processing if a valid value was entered.



    The program logic to display the input dialog box and edit the input for hours at home must be in its own method and separate from main().
    Based on the type of dwelling and the number of hours at home, use this table to determine what type of pet the user should get. Display this recommendation in a message dialog box. Your message dialog box must look like Figure 5 below. Keep in mind the recommended pet will change based on the user input.


    The program logic to determine the pet and display the message dialog box with the recommend pet must be in its own method and separate from main().
    You may not use any "global" variables, that is variables declared outside a method.
    You do not need to program a response when the user clicks the Cancel button or clicks the X in the upper right corner of the dialog. I will not test these features when I grade your application.
    Based on the requirements above, you will have a minimum of four methods:
    main( )
    a method to process the type of dwelling
    a method to process the number of hours at home
    a method to determine and display the recommended pet.


    I can't find what's wrong with my code that I am recieving the message "No main methods, applets, or MIDlets found in file."

    import javax.swing.JOptionPane;
     
    public class PetAdvice
    {
    	public void main(String[] args)
    	{	
    		String Domicile;
    		{
    			Domicile = JOptionPane.showInputDialog(null, "Input A(Apartment), H(House), D(Dorm)");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Domicile = "A";
    					break;
    				case "H":
    				case "h":
    					Domicile = "H";
    					break;
    				case "D":
    				case "d":
    					Domicile = "D";
    					break;
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String Hours;
    		{
    			Hours = JOptionPane.showInputDialog(null, "Input A(18+ Hours), B(10-17 Hours), C(8-9 Hours), D(6-7 Hours), E(0-5 Hours).");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Hours = "a";
    					break;
    				case "B":
    				case "b":
    					Hours = "b";
    					break;
    				case "C":
    				case "c":
    					Hours = "c";
    					break;
    				case "D":
    				case "d":
    					Hours = "d";
    					break;
    				case "E":
    				case "e":
    					Hours = "e";
    					break;				
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String petDetermination;
    		{
    			if (Domicile == "H")
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile == "A")
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile ==  "D")
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}
    		}
    	}	
    }
    Last edited by ZBixby; February 10th, 2013 at 07:51 AM. Reason: unsolved


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    the message "No main methods, applets, or MIDlets found in file."
    How are you trying to execute the class file? What is on the commandline you are using?

    The java program requires that there be a specific main() method defined in the class that is passed to it. If the commandline is:
    java TheClass
    then TheClass class must have the main() method.

    The main() in you code is NOT the one required by java. It is missing the static attribute.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Quote Originally Posted by Norm View Post
    How are you trying to execute the class file? What is on the commandline you are using?.
    I'm using JGrasp to write and compile the program. I thought I had the main() method defined or do I have it set in the wrong spot.

    should the main() method be static as opposed to what I have below?
    public void main(String[] args)
    	{	
    		String Domicile;
    		{


    --- Update ---

    Quote Originally Posted by Norm View Post
    How are you trying to execute the class file? What is on the commandline you are using?

    The java program requires that there be a specific main() method defined in the class that is passed to it. If the commandline is:
    java TheClass
    then TheClass class must have the main() method.

    The main() in you code is NOT the one required by java. It is missing the static attribute.

    I figured it out, the main method had to be static in order for the input windows to initiate.

    --- Update ---

    And now I have a new issue with the program. My case commands aren't working and when i enter H for house my command always exits out while A and D only resolve to the first answer on the case line.

    String petDetermination;
    		{
    			if (Domicile == "H")
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile == "A")
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile ==  "D")
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}


    --- Update ---

    And now I have a new issue with the program. My case commands aren't working and when i enter H for house my command always exits out while A and D only resolve to the first answer on the case line.

    String petDetermination;
    		{
    			if (Domicile == "H")
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile == "A")
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile ==  "D")
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Use the equals() method for comparing Strings, not the == operator.
        if (Domicile == "A")
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Quote Originally Posted by Norm View Post
    Use the equals() method for comparing Strings, not the == operator.
        if (Domicile == "A")
    So I'm trying to change it to the equals() method but I'm receiving errors both ways I tried it. I think I'm a bit lost.

    PetAdvice.java:70: error: ')' expected
    			if (Domicile equals("H");
    			            ^
    PetAdvice.java:85: error: ')' expected
    			if (Domicile equals("A"));

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    equals() is a method that belongs to a class. You need to connect the class to the method with a .

    The code in the () of the if statement is not a valid boolean expression.
    The code has a String and a call to a method(). The compiler wants the contents of the () to return a boolean value.
    Replacing the String with "asdf" and the equals() method with what it could return: false would be this:
    ("asdf" false)
    which is not a valid boolean expression.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Well that partially solved the issue. This code is all sorts of messed up I think because now if I try to return any value other then "A" it gives me my invalid entry error.

    Here's the code in it's current status

    import javax.swing.JOptionPane;
     
    public class PetAdvice
    {
    	public static void main(String[] args)
    	{	
    		String Domicile;
    		{
    			Domicile = JOptionPane.showInputDialog(null, "Input A(Apartment), H(House), D(Dorm)");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Domicile = "A";
    					break;
    				case "H":
    				case "h":
    					Domicile = "H";
    					break;
    				case "D":
    				case "d":
    					Domicile = "D";
    					break;
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String Hours;
    		{
    			Hours = JOptionPane.showInputDialog(null, "Input A(18+ Hours), B(10-17 Hours), C(8-9 Hours), D(6-7 Hours), E(0-5 Hours).");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Hours = "a";
    					break;
    				case "B":
    				case "b":
    					Hours = "b";
    					break;
    				case "C":
    				case "c":
    					Hours = "c";
    					break;
    				case "D":
    				case "d":
    					Hours = "d";
    					break;
    				case "E":
    				case "e":
    					Hours = "e";
    					break;				
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String petDetermination;
    		{
    			if (Domicile.equals("H"));
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile.equals("A"));
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile.equals("D"));
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}
    		}
    	}	
    }

    and then the part I have been working on separately

    String petDetermination;
    		{
    			if (Domicile.equals("H"));
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile.equals("A"));
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile.equals("D"));
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}

    Also when I am entering the values for the How Many Hours are you home it returns the case value for each of the cases when it does work.

    --- Update ---

    Well that partially solved the issue. This code is all sorts of messed up I think because now if I try to return any value other then "A" it gives me my invalid entry error.

    Here's the code in it's current status

    import javax.swing.JOptionPane;
     
    public class PetAdvice
    {
    	public static void main(String[] args)
    	{	
    		String Domicile;
    		{
    			Domicile = JOptionPane.showInputDialog(null, "Input A(Apartment), H(House), D(Dorm)");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Domicile = "A";
    					break;
    				case "H":
    				case "h":
    					Domicile = "H";
    					break;
    				case "D":
    				case "d":
    					Domicile = "D";
    					break;
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String Hours;
    		{
    			Hours = JOptionPane.showInputDialog(null, "Input A(18+ Hours), B(10-17 Hours), C(8-9 Hours), D(6-7 Hours), E(0-5 Hours).");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Hours = "a";
    					break;
    				case "B":
    				case "b":
    					Hours = "b";
    					break;
    				case "C":
    				case "c":
    					Hours = "c";
    					break;
    				case "D":
    				case "d":
    					Hours = "d";
    					break;
    				case "E":
    				case "e":
    					Hours = "e";
    					break;				
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String petDetermination;
    		{
    			if (Domicile.equals("H"));
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile.equals("A"));
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile.equals("D"));
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}
    		}
    	}	
    }

    and then the part I have been working on separately

    String petDetermination;
    		{
    			if (Domicile.equals("H"));
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			if (Domicile.equals("A"));
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}		
    			if (Domicile.equals("D"));
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}

    Also when I am entering the values for the How Many Hours are you home it returns the case value for each of the cases when it does work.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Your code has some problems that the compiler/IDE should tell you about. Use the javac program's -Xlint option to see the messages. Here is my commandline to compile the code:
    D:\Java\jdk1.7.0.7\bin\javac.exe -Xlint PetAdvice.java
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    I don't think my javac.exe has -xlint, it keeps returning invalid switch. Agg this is frustrating i'm looking through the code and I can't figure out why the heck the switch;case is returning all the values.

    --- Update ---

    I tried using an else if but it returned

    PetAdvice.java:99: error: 'else' without 'if'
    			else

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    The X in -Xlint is uppercase
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    When running it it returned no response in the command line does it output to a file somewhere?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    When running it
    What is the "it" you are talking about?

    One potential problem I see is that the statements following the if statements are not included in {}s. Use of {}s makes the code easier to read and will prevent future problems.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Oh sorry the -Xlint command.

    The biggest problem I'm having with this code is that it's not wanting to use the Switch Cases is it possible that my String Domicile; and String Hours; commands should have something preceding them? Like Public String? Or am I just being crazy on that.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    There is no -Xlint command. -Xlint is an option for the javac command.
    Can you copy the contents of the command prompt window and paste it here from when you compile the code?

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    One potential problem I see is that the statements following the if statements are not included in {}s. Use of {}s makes the code easier to read and will prevent future problems.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    These are the results of attempting to run javac -Xlint

    C:\Program Files\Java\jdk1.7.0_11\bin>javac -Xlint "C:\Users\Zane\Documents\Peta
    dvice.java"

    C:\Program Files\Java\jdk1.7.0_11\bin>

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Did the javac command generate a class file when it was executed?

    I'm using D:\Java\jdk1.7.0.7\bin\javac.exe -Xlint ....java
    vs 1.7.0_11

    I'll have to get the newer version to see if it has removed the warning messages.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Not that I can see other then the already made .class file in my folder from compiling in JGrasp, this has really got me stumped.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    If the javac command didn't create a .class file then there must be a problem with the way it is being executed.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Maybe. I think the problem is in my final String command in that I don't know if it needs to be a String command. It won't go by the Switch; Cases commands as it will only return the first case output in each if statement.

    String petDetermination;
    		{
    			if (Domicile.equals("H"))
    			{	switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			}
    			if (Domicile.equals("A"))
    			{	switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}
    			}		
    			if (Domicile.equals("D"))
    			{	switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}
    			}

    Is there a different way I could or should be calling this method since that "String" doesn't get called anywhere?

    --- Update ---

    Maybe. I think the problem is in my final String command in that I don't know if it needs to be a String command. It won't go by the Switch; Cases commands as it will only return the first case output in each if statement.

    String petDetermination;
    		{
    			if (Domicile.equals("H"))
    			{	switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
    			}
    			if (Domicile.equals("A"))
    			{	switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}
    			}		
    			if (Domicile.equals("D"))
    			{	switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}
    			}

    Is there a different way I could or should be calling this method since that "String" doesn't get called anywhere?

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Please post all of the current code.

    coding conventions recommend that there NOT be any code on the same line following a {
    or on the same line before a } so that these characters can be easily seen.


    I think the problem is
    Please explain. What do you enter and what does the program output?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Current code is as follows:

    //Program Name: Pet Advice
    //Author: Zane Bixby
    //Date: 09FEB13
    //Purpose: To recommend the type of pet a person should own.
     
    import javax.swing.JOptionPane;
     
    public class PetAdvice
    {
    	public static void main(String[] args)
    	{	
    		String Domicile;
    		{
    			Domicile = JOptionPane.showInputDialog(null, "Input A(Apartment), H(House), D(Dorm)");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Domicile = "A";
    					break;
    				case "H":
    				case "h":
    					Domicile = "H";
    					break;
    				case "D":
    				case "d":
    					Domicile = "D";
    					break;
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}
    		String Hours;
    		{
    			Hours = JOptionPane.showInputDialog(null, "Input A(18+ Hours), B(10-17 Hours), C(8-9 Hours), D(6-7 Hours), E(0-5 Hours).");
    			switch(Domicile)
    			{
    				case "A":
    				case "a":
    					Hours = "a";
    					break;
    				case "B":
    				case "b":
    					Hours = "b";
    					break;
    				case "C":
    				case "c":
    					Hours = "c";
    					break;
    				case "D":
    				case "d":
    					Hours = "d";
    					break;
    				case "E":
    				case "e":
    					Hours = "e";
    					break;				
    				default:
    				{
    					JOptionPane.showMessageDialog(null, "You have entered an invalid code; the application is now ending");
    					System.exit(-1);
    				}
    			}
    		}	
    		String petDetermination;
    		{
    			if (Domicile.equals("H"))
    				switch(Hours)
    				{
    					case "a":
    						JOptionPane.showMessageDialog(null, "You should get a Pot-Bellied Pig.");
    						break;
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Dog.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Snake.");
    						break;
    				}
     
    			if (Domicile.equals("A"))
    				switch(Hours)
    				{
    					case "a":
    					case "b":
    						JOptionPane.showMessageDialog(null, "You should get a Cat.");
    						break;
    					case "c":
    					case "d":
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get a Hamster.");
    						break;
    				}
    			}		
    			if (Domicile.equals("D"))
    				switch (Hours)
    				{
    					case "a":
    					case "b":
    					case "c":
    					case "d":
    						JOptionPane.showMessageDialog(null, "You should get a Fish.");
    						break;	
    					case "e":
    						JOptionPane.showMessageDialog(null, "You should get an Ant Farm.");
    						break;
    				}	
    		}	
    	}	
    }


    --- Update ---

    Quote Originally Posted by Norm View Post
    Please explain. What do you enter and what does the program output?
    When I enter H in the InputDialog no matter what value I enter into the Input Box for Hours it will return "You have entered an invalid code; the application is now ending" and when I enter D or A it will only return the first option in the Cases from petDetermination

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    You have entered an invalid code;
    Add the invalid code to the error message so you can see what the computer sees.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Quote Originally Posted by Norm View Post
    Add the invalid code to the error message so you can see what the computer sees.
    I'm honestly not sure what you mean by this.

    --- Update ---

    I noticed in my assignment details that each of the methods must be separate from the main() method.

    The program logic to display the input dialog box and edit the input for hours at home must be in its own method and separate from main().
    The program logic to determine the pet and display the message dialog box with the recommend pet must be in its own method and separate from main().
    Based on the requirements above, you will have a minimum of four methods:
    main( )
    a method to process the type of dwelling
    a method to process the number of hours at home
    a method to determine and display the recommended pet.

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    What variable has the invalid value that causes the error message to be displayed?
    Add that variable to the message so you can see what the invalid value was.
    If you don't understand my answer, don't ignore it, ask a question.

  25. The Following User Says Thank You to Norm For This Useful Post:

    ZBixby (February 10th, 2013)

  26. #25
    Junior Member
    Join Date
    Feb 2013
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Application not running. "No main methods, applets, or MIDlets found in file."

    Huh.... well I have no idea what I changed but it suddenly started working right, I was going through trying to make sure the {} were right and I might have added one in that made it correct.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  2. "possible loss of precision, found double, required int" HELP
    By kkatchh in forum Loops & Control Statements
    Replies: 3
    Last Post: November 6th, 2011, 10:50 AM
  3. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  4. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM