Java - Bug Detective - error

Hello!

Using a Macbook Air, I am working on the Bug Detective exercise at the end of the Learn Java series. I have tidied up the various errors but still have this error message:

Error: Main method not found in class Fortune, please define the main method as:
public static void main(String args)
or a JavaFX application class must extend javafx.application.Application

https://www.codecademy.com/courses/learn-java/projects/java-bug-detective?action=resume_content_item

Thank you for your support!

Hi @xiibluewords - welcome to the forum.

Please note that the link you’ve provided takes us to the project, but does not allow us to see your code.

Please copy and paste the problematic program into a forum post, making sure to use the code formatting button (</>) in the editor.
capture
The </> button will insert a block into your post, like this:
capture_r
and when it’s posted to the forum, it’ll look like this:

public static void some_method() {
    some  code....
}

Once we’ve got the code, we can take a look and see if we can help. :slight_smile:

2 Likes
import java.lang.Math;

class Fortune {

  public int generateRandom() {
    
    return (int)(Math.random() * 10);
    
  }
    
  public static void Main(String[] args) {

    Fortune fortuneCookie = new Fortune();
    int fortune = fortuneCookie.generateRandom();
    
    if (fortune == 0) {

      System.out.println("Flattery will go far tonight.");
    
    } else if (fortune == 1) {
        
      System.out.println("Don't behave with cold manners.");
    
    } else if (fortune == 2) {
        
      System.out.println("May you someday be carbon neutral");
        
    } else if (fortune == 3) {
        
      System.out.println("You have rice in your teeth.");
        
    } else if (fortune == 4) {
        
      System.out.println("A conclusion is simply the place where you got tired of thinking.");
        
    } else if (fortune == 5) {
        
      System.out.println("No snowflake feels responsible in an avalanche.");
        
    } else if (fortune == 6) {
        
      System.out.println("He who laughs last is laughing at you.");
        
    } else if (fortune == 7) {
        
      System.out.println("If you look back, you'll soon be going that way.");
        
    } else if (fortune == 8) {
        
      System.out.println("You will die alone and poorly dressed.");
        
    } else if (fortune == 9) {
        
      System.out.println("The fortune you seek is in another cookie.");
        
    }
     
  }
  
}
1 Like

You may feel like kicking yourself, but don’t. We’ve all banged our heads against the wall looking for these types of errors. Compare your code above to the error message:

1 Like

Thank you, @midlindner. I appreciate your help!

2 Likes