Reputation: 1
Hi I'm new to java and facing the below error
i'm trying to run this script
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo {
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver", "C:\\javacoding\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://google.com");
}
}
But get this error when i try to run it
Error: Main method not found in class Demo, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
Upvotes: 0
Views: 1926
Reputation: 1
In the public static void Main()
gives the error:
Error: Main method not found in class Main1
define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend application.Applicationjavafx
if you change capital M
to small m
in main the error will not occur
Upvotes: 0
Reputation: 1277
Regarding the docs with example and as error message says
Error: Main method not found in class Demo, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
The main is in place, but inheritance not, you will need to extend javafx.application.Application
, so assuming that should fix the issue:
replace the class declaration as public class Demo
to public class Demo extends javafx.application.Application
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo extends javafx.application.Application{
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver", "C:\\javacoding\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://google.com");
}
}
Or just public class Demo
to public class Demo extends Application
with import javafx.application.Application;
(in the import section of the class)
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import javafx.application.Application; //added
public class Demo extends Application{
public static void main(String [] args) {
System.setProperty("webdriver.chrome.driver", "C:\\javacoding\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://google.com");
}
}
It seems you did not created the correct type of the project in your IDE, maybe re-creation will be needed (like eg. in case of maven project you need some additional files like pom.xml, etc.)
Upvotes: -1