• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.lang.NoSuchMethodError: main

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea why this program is not running?



Error
Exception in thread "main" java.lang.NoSuchMethodError: main


03/07/2011 21:42 <DIR> .
03/07/2011 21:42 <DIR> ..
03/07/2011 21:40 640 SimpleThread.class
03/07/2011 21:42 404 SimpleThread.java
03/07/2011 21:41 521 SimpleThreadTest.class
03/07/2011 21:41 302 SimpleThreadTest.java
4 File(s) 1,867 bytes
2 Dir(s) 37,588,905,984 bytes free

>javac SimpleThread
error: Class names, 'SimpleThread', are only accepted if annotation processing is explicitly requested
1 error

>javac SimpleThreadTest
error: Class names, 'SimpleThreadTest', are only accepted if annotation processing is explicitly requested
1 error

>

Somehow it runs in Eclipse, but the CLI and TextPad don't compile
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must specify the filename with the javac command:

javac SimpleThreadTest.java

Not just the class name. (Did you pay attention to the error message that the compiler printed?).
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you also need to keep the name of public class and file name same, otherwise it won't compile.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Javin. So will the following modifications will make the code work?

1. Have the file name as SimpleThreadTest.java
2. Change the SimpleThread class from public to default
3. Compile only SimpleThreadTest & run only SimpleThreadTest

Above changes i think should be made since main() method is present only in the SimpleThreadTest class. Correct me.
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely correct , though I haven't run it , you are the step by step guide master (was reading another thread where you have provided step by step solution )
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:yes Javin. So will the following modifications will make the code work?

1. Have the file name as SimpleThreadTest.java
2. Change the SimpleThread class from public to default
3. Compile only SimpleThreadTest & run only SimpleThreadTest

Above changes i think should be made since main() method is present only in the SimpleThreadTest class. Correct me.


Yes excuse my typos, why does the class have to be default and cannot be public?
I was expecting the code within the run() method to run, however it does not, any idea why?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because you did not start the thread. Just creating a Thread object is not enough, you have to call start on it.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Because you did not start the thread. Just creating a Thread object is not enough, you have to call start on it.


Well, I tried mimicking this tutorial, however, I still get the same error:

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully read and follow John Jai's advice, that will solve your problem, with one extra point: make class SimpleThreadTest public.

John Jai wrote:yes Javin. So will the following modifications will make the code work?

1. Have the file name as SimpleThreadTest.java
2. Change the SimpleThread class from public to default
3. Compile only SimpleThreadTest & run only SimpleThreadTest

Above changes i think should be made since main() method is present only in the SimpleThreadTest class. Correct me.


Please make an effort to understand why this will solve the problem.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Carefully read and follow John Jai's advice, that will solve your problem, with one extra point: make class SimpleThreadTest public.

John Jai wrote:yes Javin. So will the following modifications will make the code work?

1. Have the file name as SimpleThreadTest.java
2. Change the SimpleThread class from public to default
3. Compile only SimpleThreadTest & run only SimpleThreadTest

Above changes i think should be made since main() method is present only in the SimpleThreadTest class. Correct me.


Please make an effort to understand why this will solve the problem.


Sorry, indeed this works, the problem is that the compiler requires a class named Dog within a file named Dog.java, and, so on, which is a petty mistake



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic