• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting java.lang.NoSuchMethodError: main error! thanks =)

 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i keep getting java.lang.NoSuchMethodError: main
Exception in thread "main" when i try to run it but it complies fine. Can anyone advise? Thanks!

Also i would like to ask how would i save the student name and ID into an arraylist and retrieve it from the arraylist to delete? Thanks for help!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
um.... you don't have a main method in the code you posted. a class is not require to have a main to compile, only to run.
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
winnie Lim wrote:
Also i would like to ask how would i save the student name and ID into an arraylist and retrieve it from the arraylist to delete? Thanks for help!


Id is a Key and Student name is values, that's sound good for Map collections
 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there anything wrong with my School class?

i can't seem to call the addStudent, removeStudent, methods in my public class SchoolApp. i get error "cannot find symbol method addStudent();"

thanks alot for the java.lang.NoSuchMethodError! solved!

 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be calling addStudent() etc from another class, SchoolApp, and SchoolApp hasn't got an addStudent() method.

You need to create a School object in that main method, then invoke the methods on that object.

By the way: your addStudent method in the School class doesn't seem to do anything. It asks for the Student's name, but doesn't do anything with it. It that because the class is incomplete?
 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You appear to be calling addStudent() etc from another class, SchoolApp, and SchoolApp hasn't got an addStudent() method.

You need to create a School object in that main method, then invoke the methods on that object.

By the way: your addStudent method in the School class doesn't seem to do anything. It asks for the Student's name, but doesn't do anything with it. It that because the class is incomplete?


yes the code is incomplete... i'm supposed to store it into a arraylist and retrieve it.

sorry to ask but can you teach me how to create a School object in the main method? I know it sounds stupid but i really am new and its a pressing assignment.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you create a new object of any class? You do the same with the School class.
And please don't go saying questions are urgent.
 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:How do you create a new object of any class? You do the same with the School class.
And please don't go saying questions are urgent.


erm... i really don't know how to create a new object of anything! i already tried looking through all the online tutorials but i really can't get what they mean or what how the object class in created. Please if you can, just help me out here.
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This site discusses how to create a new object. It has some things that are out of your scope, but it should give a decent description on creating an object.

Creating Objects
 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks!

but after i declare eg School sch = new School ();

what do i do to invoke the methods in the object?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The longer I post on this forum, the more people will realize I'm full of links!

Link

That should describe how to invoke the methods of an object.
 
winnie Lim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks! will read through and try to understand on my own.

you guys have been a great help thanks a million!!!
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confident that link will supply all the information you need.

And . . . you're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic