The error states Error main method not found in class. Please define the main method as:
public static void main(String[] args).
Eclipse was working for me a few days ago, but now it just gives me that message
an example would be
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
Check if exists any error in your project. Not just the compilation errors. Click on project and check the "Problems" view in Eclipse. You need to remove all of "Errors".
First clean your project Using Project-->Clean and then build it again.
Also make sure that your build path is properly set.
I ran into the same issue. Just clean your project..save your project and then run it.
Check whether you have created a class with the name "String". If you have created a class with the name "String", the compiler will not be able to resolve the conflict between 2 classes i.e. java.lang.String and your String class therefore it won't recognize the main method.
So just remove that String class or rename it.It happened to me also.. I resolved using this only.
I ran into this problem also when I moved the location of the main method in my program to another file in the same program. If this is what happened to you, the fix is to go to the top of Eclipse near the bug and play icons and change the "Run as..." field to "Java application" from whatever its previous location was.
Try to resturt Eclipse in a new workspace.
Maybe you are creating 2 classes in the same package or u have defined one of your defined class name as "String". If you have then change that classname to something else , because at that time compiler cannot differentiate between java.lang.String and your user defined class "String". So jst chage the name of that String class.
Related
I am referencing PlayerUtil.getMovementSpeed(player); in my Speed class, and in my PlayerUtil class, I have the method defined as:
public static double getMovementSpeed(Player player) {
//my code here
}
But whenever the getMovementSpeed method is referenced in my other classes, it throws this error:
java.lang.NoSuchMethodError: net.Swedz.util.PlayerUtil.getMovementSpeed(Lorg/bukkit/entity/Player;)D
I thought it may be that Eclipse was exporting incorrectly, but I rebooted it and tried again with no avail.
EDIT: I did try decompiling the exported jar, and the public static double getMovementSpeed(Player player) method does exist in the exported jar.
EDIT: My friend is also having a similar issue, and is using IntelliJ, so Eclipse is not the issue.
EDIT: Class definition for PlayerUtil:
package net.Swedz.util;
public class PlayerUtil implements Listener {
//getMovementSpeed is defined in here
}
Class definition for Speed:
package net.Swedz.hack.detect.move;
public class Speed implements Hack, Listener {
//my detection methods and method containing PlayerUtil.getMovementSpeed(player);
}
SOLUTION: I found on my own that I had classes conflicting between two plugins on my server. I had one jar with net.Swedz.util.PlayerUtil and another with net.Swedz.util.PlayerUtil both with different contents. I added my project name in all lower case after the net.Swedz and it seems to have fixed it!
Thanks!
This is a very simple to troubleshoot.
you have used that method and you were able to compile that class which uses this method.
so that means at compile time it reefers the class PlayerUtil which has this method.
But runtime class loader has loaded the class PlayerUtil which doesn't contain this method.
now what you have to do is just find out where that class has been loaded from (at run time)
if you can recreate the problem while it is running using eclipse/IDEA follow these steps.
(if it runs in in application server or standalone application, then start the application server or application with debug enabled.and you can do remote debug from your IDE).
put a break-point where exception was thrown (where you call this method).
start to debug , it will hit the break-point.
then evaluate this expression PlayerUtil.class.getResource("PlayerUtil.class")
4.you can find the path where the class was loaded from.
now you have two options , decompile the class and check whether that method is these (same return type, same name , same args).
or in debug , you can evaluate PlayerUtil.class.getDeclaredMethods() to find out.
So you can solve the problem by rectifying the class path entries if it was loaded from a wrong place.
I use soot for instrumenting a java program. I know for adding invocation to specific class in soot, we must set "Soot class-path" to the directory contains that class, .class file. So I do this in main method of main class. I bring the snippet of code bellow
public class Main {
public static void main(String[] args) {
Scene.v().setSootClassPath("/home/j/IdeaProjects/Test_1/classes:/home/j/IdeaProjects/Test_1/libs/rt.jar:home/j/IdeaProjects/Test_1/libs/jce.jar");
PackManager.v().getPack("jtp").add(new Transform("jtp.RetIns", new ExIns()));
....
But when I want to use "Insop" class which resides in classes folder, by following code in Exins method:
static SootClass Ins;
static
{
Ins= Scene.v().loadClassAndSupport("Insop");
}
I get the error
Caused by: java.lang.RuntimeException: couldn't find class: Insop (is your soot-class-path set properly?)
I should mention that I use ubuntu 14.4 32 bit and I run the code on intellij.
I can not find what is my mistake. could you please help me.
I finally find the problem. I don't know why, but I should set "soot class-path" with relative path. For my project for example it should set as follow:
Scene.v().setSootClassPath("classes:libs/rt.jar:libs/jce.jar");
I created one Java program and create jar file for that program in the program class name is DateFormate and static method is demo()
Then added that jar file to iReport file then i call that static method as
new com.it.DateFormate.demo()
then this error raised:
com.it.DateFormate cannot be resolved to a type
If it is a static method the call will be
com.it.DateFormate.demo()
Hence, no new
To make it work the class needs to be in classpath, if you like it to work inside of your IDE make sure you add a jar (to the IDE) that contains this class.
I just added some code to a project and suddenly I get these errors. The class in question does have a main method and the other class ClientLauncher in the client package exists. I checked and the classes have the correct package listed in them. Any suggestions on what I should check? Thanks.
Error: Could not find or load main class client.ClientLauncher
selection does not contain a main type
I'm not sure if this is what was going on, because I had deleted the last project and started over. But I just got a similar error and thought I'd post this in case it helps someone. In the process of doing a similar project, I forgot to include "String args[]" in the main method definition and only had"
public static void main(). This gave a similar "does not have main method". The moment I added the above and had:
public static void main(Strings args[]);
then the error went away and the code ran correctly.
I am using NetBeans IDE and have created a new project. The new project includes a Main.java.
Is it necessary to have it named Main.java, or can I rename the Main.java into another name? If so, how can I do this? When I try to right-click Main.java, there is no rename option. I thought it was possible.
There should be a menu item called
Refactor --> Rename
Link from NetBeans Wiki
Your name can be anything, as long as you have a
public static void main(String[] args)
in it (This is only if you want this class to be the entry point when you run your application).
You can call the file <whatever you like>.java, but the name of the class in that file must match the new name you give to the file.
So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main to public class MyCoolClass.
you can even have the simpler way,click on the file_name.java in the Projects panel,wait for a sec and click one more time (just as you rename any other folder/file).It will allow you to replace the new name and then it will popup a window asking whether you want to refactor or not...
you got to use the refractor, as it is the safest way to do such actions