0

I am trying to run this class but I am getting an error that main method is not found although I have defined the public static void main (String [] args){}

This is my class file :

package jDBCLearn;

public class Main {
  public static void main(String[] args) {

    try {
      Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "Ronitpandey123");
      System.out.println("Connection Succesful");
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}

This is the project explorer:

Image of project explorer

This is the error log :

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

This is the run configuration:

Image of run configuration

This is the dependencies folder:

Dependency folder image

This is the source folder:

image of source folder

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Ronit Pandey
  • 153
  • 1
  • 8
  • I really cannot understand this error the main method is already present still it is throwing this error . Please tell me how to fix this error – Ronit Pandey May 29 '23 at 09:33
  • Try and clean your build before running again. – Federico klez Culloca May 29 '23 at 09:41
  • 1
    is that the only error? see this exclamation mark [here](https://i.stack.imgur.com/2xSbs.png) - it often indicates some (project) configuration error - check the `Problems` view if there is some error there (I also wonder the `.classpath` entry under Dependencies) – user16320675 May 29 '23 at 09:47
  • To troubleshoot this, it via the cli but first compile it `javac src/jDBCLearnProject/Main.java` and then run it via `java src/jDBCLearnProject/Main.java` – Valerij Dobler May 29 '23 at 10:01

0 Answers0