• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception in main thread

 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 >
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is "the exception"? In which line does it occur?
 
Swastik Dey
Rancher
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exception are you getting?
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1625
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code which you pasted is working fine. Paste the code which exactly gave you the error so that we can help.
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which command are you using to execute it? It should be something like "java Dog".
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using java Animal

why should i use java Dog ??
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was using java Animal


thanks sir , that was something silly
 
suavedeep kaur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic