File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes exception in main thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception in main thread" Watch "exception in main thread" New topic
Author

exception in main thread

suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
class Animal{
static void dostuff(){
System.out.print("a");
}
}

class Dog extends Animal{
static void dostuff(){
System.out.print("d");
}

public static void main(String [] args){
Animal [] a={new Animal(), new Dog(), new Animal()};
for (int x=0;x<a.length; x++)
a[x].dostuff();
}

hi , i am getting the exception .Please can anyone explain me the reason >



Suavedeep kaur
SCJP
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Is it a exception or a compiler error? Can you post it here? As I see you are missing a curly brace at the end of the Dog class.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
What is "the exception"? In which line does it occur?


Ping & DNS - my free Android networking tools app
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

What exception are you getting?


Swastik
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
I am able to compile the program but i cant execute it it says...

Exception in thread "main" java.lang.NoSuchMethodError:main
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

I hope you have not changed the method signature of main comparing to the one you have pasted here, if I am not very wrong we normally get this error when we dont have any main method like this
public static void main(String [] args)
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
i have just pasted the code ...but still i am not able to get why am not able to execute it ???
Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

The code which you pasted is working fine. Paste the code which exactly gave you the error so that we can help.


SCJP 5.0 and now fighting with ExtJS
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

suavedeep kaur wrote:i have just pasted the code ...but still i am not able to get why am not able to execute it ???


How are you compiling/running the code? Can you post the commands you used? And how you named the source file?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
Which command are you using to execute it? It should be something like "java Dog".
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
i am using java Animal

why should i use java Dog ??
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
i was using java Animal


thanks sir , that was something silly
suavedeep kaur
Ranch Hand

Joined: Jun 02, 2008
Posts: 36
I got it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception in main thread