Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help plss

 
msjei asuncion
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im doing a program that will let me sort names out..here'a my code:



for some reason im not getting any error when i compiles it its just that it's giving me no result it says" Exception in thread "main" java.lang. nosuchmethodorError" what does this mean..sorry im new in JAVA..

thanks
 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all it tells you...b/c it would be nice to know what method it is talking about...

but just by looking at your code...if i'm not mistaken your equals method is not written correctly.....you need t retrun a true or false
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equals method is fine. In fact the whole class is well -written (IMO). The error that you are getting is because you can't run a java program without providing an entry point, a main() method. I would consider writing a Name1Test (or some people call it a Driver class) class to test the methods of your Name1 class. In this class you can provide a main method, and call the constructor and all the methods of your Name1 class. The signiture of the main method must be:


HTH

Garrett
[ February 04, 2006: Message edited by: Garrett Rowe ]
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equals method is fine.

Well it depends on what 'fine' means. The equals method is 'fine' if you're not trying to override the Object's equals() method.
But then what would be the point?
All overriden equals() method MUST have the following signature:

Regards
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think the point of the method was to override the equals method in Object class. In many introductory texts, including the one I learned from, you are taught to write an equals method long before you are taught to about inheritance and thus about overwriting a method in a super class. The point is to help the beginner programmer think about what it means for two instances to be "equal" without being "==". Also satisfying the contract for overriding equals in object class is usually beyond the scope of the introductory chapters in a textbook.
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I don't think the point of the method was to override the equals method in Object class.

How can you say that from the code snippet shown by the OP?
I've seen many java beginners who have made the same mistake while their intention was to override Object equals().
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jean-Francois Briere:
> I don't think the point of the method was to override the equals method in Object class.

How can you say that from the code snippet shown by the OP?
I've seen many java beginners who have made the same mistake while their intention was to override Object equals().


You're right, that was an opinoin not supported OP's post.


But then what would be the point?

This was actually the question I was trying to address.
[ February 04, 2006: Message edited by: Garrett Rowe ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After this lovely, long, and ultimately pointless discussion, perhaps we could return to the OP's error? When s/he "starts the program", it says something about "NoSuchMethodError." This is precisely what you see if you try to launch a class from the command line that doesn't have a main() routine -- and his class does not have one.

msjei, please ignore the previous posts; you could come back to them when you've learned some more Java. Right now, all you need to know is that when you start a class by running, say,

java Name1

Java looks for a method that looks like

public static void main(String[]) {
// SOMETHING
}

Where the "// SOMETHING" is replaced by code that does whatever you want your program to do when you run it. There's nothing wrong with the class you've written, really; it's just that it doesn 't have a "main" routine, so Java doesn't know how to run it. Add a "main" method, and in that method, write some code to use Name1 objects to do something. Create one, call input(), call output(), etc.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
After this lovely, long, and ultimately pointless discussion, perhaps we could return to the OP's error? When s/he "starts the program", it says something about "NoSuchMethodError." This is precisely what you see if you try to launch a class from the command line that doesn't have a main() routine -- and his class does not have one.

msjei, please ignore the previous posts; you could come back to them when you've learned some more Java. Right now, all you need to know is that when you start a class by running, say,

java Name1

Java looks for a method that looks like

public static void main(String[]) {
// SOMETHING
}

Where the "// SOMETHING" is replaced by code that does whatever you want your program to do when you run it. There's nothing wrong with the class you've written, really; it's just that it doesn 't have a "main" routine, so Java doesn't know how to run it. Add a "main" method, and in that method, write some code to use Name1 objects to do something. Create one, call input(), call output(), etc.


Just like I said in my first reply. :roll:
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Garrett Rowe:


Just like I said in my first reply. :roll:


I'm sorry Garrett, you're right. I missed the point of your post because is was buried in the middle of all this other stuff. Props, peace out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic