NoSuchMethodError

Hello. When I try to run my program I get the following error message "Exception in thread "main"java.lang.NoSuchMethodError:main My program will compile fine, but will display this message when I try to run it. However, when I try other programs they run fine. Does anyone have any suggestions or ideas. Thanks. Here is my code

Hi Troy I guess that you have named your .java file Player.java, right? We have to do following changes to make it work, 1. Remove 'public' keyword from 'public class Player {' statement 2. Add 'public' keyword to 'class Player1' statement (I guess both of these classes are written in the same file) Try making these changes and compile/run see if it works. Here, the issues is, "java always tries to find main method in the 'public class' with the name we provide to the .java file. ie. if we have a file Test.java and public class Test in there then it will try to find main in Test class. Now, here you have Player and Player1, main is in Player1 but Player1 is not public and you might have named the file to Player.java. So it is trying to find main method in Player which is not there hence the error. Regards Maulin

Troy Johnson

Greenhorn

Posts: 20

posted 14 years ago

Hello. I made the changes you suggested. I ran the program and got the following error message this time: Exception in thread "main"java.lang.ArithmeticException:/by zero at Player1.main<Player1.java:62>

Hi Troy sure u will get this error b/c u try to divide a no. with Zero, so to avoid this divide in place of avg=(9/counter++);you should try this,means start dividing by 1; avg=(9/++counter);

Troy Johnson

Greenhorn

Posts: 20

posted 14 years ago

Hello. Thanks for your help everyone. I was able to run the program without any error messages. However, I dont have anything printing or displaying on the screen. Am I doing something wrong. I am trying to get the program to display the player information as such: Tom Smith (average = 400.0) is out or Tom Smith (average = 400.0) gets a hit. Any other suggestions. Thanks again.

S Rubia

Greenhorn

Posts: 23

posted 14 years ago

well Troy the problem is in ur for loop for( int i = 3; i < 9; counter++) as a for loop starts it initialize i=3 then checks condition if(i<9) so it is true start execution fill the array wiyh player objs and then increments counter and then again checks the condition wheather i<9 or not so as there is no increment in i it will always be true ,and loop will never ended so instead of above try for( int i = 3; i < 9; i++) i think no need to increament counter in for loop if u want to increase counter twice use simply counter+=2; avg=(9/counter);

"Knowledge Seaker", Your display name is still not valid. You have been asked to change your display name to a valid value on several occasions. For an example, see here. We require that your display name be two words: your first name, a space, then your last name. Fictitious names are not allowed. Please edit your profile soon, since accounts with invalid display names get deleted. Dave