Main method not found even if I've declared it
As said in my comments, looks like you've declared a String
class among your own classes. To prove this, I've created a basic example:
class String {
}
public class CarelessMain {
public static void main(String[] args) {
System.out.println("won't get printed");
}
public static void main(java.lang.String[] args) {
System.out.println("worked");
}
}
If you execute this code, it will print "worked"
in the console. If you comment the second main
method, the application will throw an error with this message (similar for your environment):
Error: Main method not found in class edu.home.poc.component.CarelessMain, please define the main method as:
public static void main(String[] args)
Error: Main method not found in class inter333, please define the main method as: public static void main(String[] args)
You need to actually call your readFiles() method from the main class to start it and also move your class variables to be under your class declaration.
public class inter333 {
List<String> SampleStringA = new ArrayList<String>();
List<String> SampleStringB = new ArrayList<String>();
File SampleStringAFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1ma.txt");
File SampleStringBFile = new File("C:\\Users\\Trapper\\Desktop\\SampleStrings1mb.txt");
BufferedReader reader = null;
public static void main(String[] args) {
readFiles();
}
/*Other methods*/
}
Java Runtime error say main method not found for all the program
First of all uninstall java by going into => control panel > program
delete java folder form your C: drive from programfile86 and programfile and if you find folder named as sun delete it as well
In run type appdata this will show you some folder goto each folder and delete file with name of java or sun. Do this for all the folder avilable in this directory
In run type regedit and goto HKEY_USER_DATA and HKEY_LOCAL_MACHINE one by one and then goto software in that delete javasoft folder if you find .. do this in both the folder
delete all the stuff mention above if you find if you don't its ok leave and move to next step.
and then restart your PC
and reinstall java
Error :: Main method not found in class
To start a java program you need the main method which not define in your code you can make it like this :
public class Test {
public void printPhoto(int width, int height, boolean inColor) {
System.out.println("Width = " + width + " cm");
System.out.println("Height = " + height + " cm");
if (inColor) {
System.out.println("Print is Full color.");
} else {
System.out.println("Print is black and white.");
}
// printPhoto(10, 20, false); // Avoid a Stack Overflow due the recursive call
}
//main class
public static void main(String[] args) {
Test tst = new Test();//create a new instance of your class
tst.printPhoto(0, 0, true);//call your method with some values
}
}
Error: main method not found in class please define the main method as: public static void main(String[] args)
I am not sure how you are executing it.
I have saved the above code as example.java in my machine and used the following commands in command prompt
For Compiling: javac example.java
For Executing: java example
Note that the main method is in example class so you have run the example class not the Box class
Edit:
Technically any java code can be compiled but for running a standalone application, the main method is needed. Even when you save the file as Box.java and compile it, there will be no compilation errors. But for running JVM needs main method. so you have to run example class not the box class
Related Topics
How to Programmatically Configure Jaxb
Any Recommended Java Profiling Tutorial
When Using == for a Primitive and a Boxed Value, Is Autoboxing Done, or Is Unboxing Done
Spring Web MVC - Validate Individual Request Params
Is There a Sophisticated File System Monitor for Java Which Is Freeware or Open Source
Java String Concatenation with + Operator
How to Compress a String in Java
How to Calculate the Elapsed Time of an Event in Java
How to Append a Node to an Existing Xml File in Java
Getting Java.Lang.Reflect.Invocationtargetexception While Adding a Button to Layout
How to Round Time to the Nearest Quarter Hour in Java
How to Determine the Ip of My Router/Gateway in Java
Collision Detection Between Two Images in Java
Drawing a Component to Bufferedimage Causes Display Corruption
Jsp Generating Excel Spreadsheet (Xls) to Download
Make Simpledateformat.Parse() Fail on Invalid Dates (E.G. Month Is Greater Than 12)