aspose file tools*
The moose likes Beginning Java and the fly likes need help plss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help plss" Watch "need help plss" New topic
Author

need help plss

msjei asuncion
Greenhorn

Joined: Feb 04, 2006
Posts: 1
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

Joined: Feb 03, 2006
Posts: 106
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

Joined: Jan 17, 2006
Posts: 1296
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 ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
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

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Mar 03, 2004
Posts: 101
> 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

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help plss