-2
package concurrencyTest;

public class concurrencyTest implements Runnable
{    
    @Override
    public void run() 
    {        System.out.println("Hello from a thread!");    }


    public static void main(String[] args)
     {
         concurrencyTest c = new concurrencyTest();
         Thread t = new Thread(c);
         t.start();
     }
}

Hi, I'm just trying to get my java concurrency test to run. But I'm getting this error :

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

I'm guessing that somewhere, in the myriad of project directories and subfiles that a java program needs to run, the name of the project or class has been wrongly referenced in lowercase letters. I've manually been thru all the files I can find that span from the root directory and renamed any instance of lowercase 'concurrencytest'. But still it seems the compiler finds a reference to lowercase concurrencytest and so refuses to compile. Any idea where this reference may be?

My root directory, source directory, and java code file are all called 'concurrencyTest'

edit amended the original code for this question to include 'static' in the main method definition. Doing this was necessary but has not fixed the problem.

gristy
  • 487
  • 1
  • 3
  • 7
  • 3
    `public void main` are you sure the error should not be interpreted literally? – Federico klez Culloca Jun 25 '18 at 09:38
  • Possible duplicate of [Why is the Java main method static?](https://stackoverflow.com/questions/146576/why-is-the-java-main-method-static) – fvu Jun 25 '18 at 09:41
  • 1
    The error messages states *... please define the main method as: public static void main(String[] args) ...*. Comparing it to your main method signature points out that your one is not `static`. Just make it `static` and the error loses its origin. – deHaar Jun 25 '18 at 09:43
  • Please define the main method as: public **static** void main(String[] args) – Peter Lawrey Jun 25 '18 at 09:45
  • Looks like netbeans thinks your package is called `concurrencytest` with a lowercase `t`. In other news, conventions about naming things are there for a reason. Don't try to fight them unless you know what you are doing and have a good reason to. – Federico klez Culloca Jun 25 '18 at 09:59
  • 1
    The class that you posted is called `concurrencyTest.concurrencyTest` and that is how you need to capitalize it to invoke it. – Erwin Bolwidt Jun 25 '18 at 10:02

2 Answers2

1

You wrote the main definition wrong. You should change it as below:

public static void main(String[] args) {
    // ...
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
duyuanchao
  • 3,863
  • 1
  • 25
  • 16
0

I found a reference to 'concurrencytest' in the meta file ...\concurrencyTest\nbproject\project.properties So I changed it to 'concurrencyTest'

Also when NetBeans can't find the expected main method in the class it expects, it opens a 'RunProject' window where it lists main methods from classes it has found. For me it found a main in 'concurrencyTest' so I selected it.

One of these actions solved the problem, but not sure which one.

gristy
  • 487
  • 1
  • 3
  • 7