Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?).
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you also need to keep the name of public class and file name same, otherwise it won't compile.
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic