Probably an obvious mistake

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Probably an obvious mistake

 
0
  #1
Mar 14th, 2007
Hi, I cannot for the life of me figure out why I keep getting the error message, "cannot find symbol method methodname()" when I try to call methods from another method. I have tried changing the main method so its not static but it makes no difference.

Anyone who could shed light on the issue, it would be greatly appreciated.

Thanks.

  1. import java.io.*; //import API to allow input of characters
  2. import java.util.Vector; //import API to allow Vector functionality
  3.  
  4. class Details {
  5.  
  6. String name = null;
  7. String artist = null;
  8. String year = null;
  9. String genre = null;
  10. String rating = null;
  11.  
  12. Vector v = new Vector();
  13.  
  14. public void newcd() {
  15.  
  16. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  17.  
  18. System.out.println("CD Name: ");
  19.  
  20. try { //Reads keyboard input and acts accordingly
  21. name = stdin.readLine();
  22. }catch (IOException ex) {
  23. System.out.println("Problem reading from the keyboard"); }
  24.  
  25. System.out.println("Artist: ");
  26.  
  27. try { //Reads keyboard input and acts accordingly
  28. artist = stdin.readLine();
  29. }catch (IOException ex) {
  30. System.out.println("Problem reading from the keyboard"); }
  31.  
  32. System.out.println("Year of album: ");
  33.  
  34. try { //Reads keyboard input and acts accordingly
  35. year = stdin.readLine();
  36. }catch (IOException ex) {
  37. System.out.println("Problem reading from the keyboard"); }
  38.  
  39. System.out.println("Genre: ");
  40.  
  41. try { //Reads keyboard input and acts accordingly
  42. genre = stdin.readLine();
  43. }catch (IOException ex) {
  44. System.out.println("Problem reading from the keyboard"); }
  45.  
  46. System.out.println("Rating: ");
  47.  
  48. try { //Reads keyboard input and acts accordingly
  49. rating = stdin.readLine();
  50. }catch (IOException ex) {
  51. System.out.println("Problem reading from the keyboard"); }
  52.  
  53. Details disc = new Details ();
  54. disc.name = name;
  55. disc.artist = artist;
  56. disc.year = year;
  57. disc.genre = genre;
  58. disc.rating = rating;
  59.  
  60. v.add(disc);
  61. }
  62.  
  63. }
  64. public class CDSystem { //main class
  65.  
  66. public static void main (String [] args) { //main method containing menu system
  67.  
  68. String input = null; //initialising input string
  69. int iInput;
  70. int ixInput;
  71.  
  72. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  73.  
  74. System.out.println("Welcome to your CD Collection"); //commands to display menu on screen
  75. System.out.println("Select an option from the menu:");
  76. System.out.println("1: Add a new CD");
  77. System.out.println("2: Display CDs by artist");
  78. System.out.println("3: Display CDs by genre");
  79. System.out.println("4: Display all albums ascending by year");
  80. System.out.println("5: Display all albums descending by rating");
  81. System.out.println("Press any other key to exit");
  82.  
  83. try { //Reads keyboard input and acts accordingly
  84. input = stdin.readLine();
  85. }catch (IOException ex) {
  86. System.out.println("Problem reading from the keyboard");
  87.  
  88. iInput = Integer.valueOf(input); // convert String to Integer
  89. }
  90. if (iInput == 1) {
  91. newcd();
  92. }
  93. if (iInput == 2) {
  94. artistdisplay();
  95. }
  96. if (iInput == 3) {
  97. genredisplay();
  98. }
  99. if (iInput == 4) {
  100. yeardisplay();
  101. }
  102. if (iInput == 5) {
  103. ratingdisplay();
  104. }
  105. else {
  106. System.out.println("Thank you for using CDSystem");
  107. }
  108. }
  109. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Probably an obvious mistake

 
0
  #2
Mar 15th, 2007
Originally Posted by san_fran_crisko View Post
  1. if (iInput == 1) {
  2. newcd();
  3. }
  4. if (iInput == 2) {
  5. artistdisplay();
  6. }
  7. if (iInput == 3) {
  8. genredisplay();
  9. }
  10. if (iInput == 4) {
  11. yeardisplay();
  12. }
  13. if (iInput == 5) {
  14. ratingdisplay();
  15. }
  16. else {
  17. System.out.println("Thank you for using CDSystem");
  18. }
  19. }
  20. }
If I understand correctly you try call this methods to do something?
I don't see any place in your code where you declare it, so I asume there in other class. To call this method from second class you do following
  1. SecondClass secondClass = new SecondClass();
  2. if (iInput == 1) {
  3. secondClass.newcd();
  4. }

Hope this helped, if not please provide detailed problem description
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Probably an obvious mistake

 
0
  #3
Mar 15th, 2007
1. Give complete information. E.g. error msg (as printed on your console) so we know which line are we talking abt... ??
2. Is the error runtime or compile time??
3. Without that info all I can say/guess is there might be some unsatisfied linking kinda error. Assuming it's a runtime error of course. Hope you got it..

I meant something like this.
Last edited by thekashyap; Mar 15th, 2007 at 5:53 pm. Reason: Added teh link
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Re: Probably an obvious mistake

 
0
  #4
Mar 15th, 2007
Thanks for replying peter.

Firstly, apologies for not pointing out that those other classes and methods do not exist yet. Work in progress.

Secondly, thanks for the advice. At first it didn't work but it was because I had a random word "Details" in my code which Java was thinking was a variable and was mixing it up with the class called Details too. Once I isolated that, your code solved the problem.

Many thanks.

Crisko.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Re: Probably an obvious mistake

 
0
  #5
Mar 15th, 2007
Thanks man, eventually got it solved (see above/below) but I'll bear that in mind in future.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Re: Probably an obvious mistake

 
0
  #6
Mar 15th, 2007
Got another problem

Can anyone tell me why my menu system doesn't work? Whenever I enter a value when its running it exits every time. E.G. It will not run the newcd() method when I enter one.

  1. if (iInput == 1) {
  2. newcd();
  3. }
  4. if (iInput == 2) {
  5. artistdisplay();
  6. }
  7. if (iInput == 3) {
  8. genredisplay();
  9. }
  10. if (iInput == 4) {
  11. yeardisplay();
  12. }
  13. if (iInput == 5) {
  14. ratingdisplay();
  15. }
  16. else {
System.out.println("Thank you for using CDSystem");
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Probably an obvious mistake

 
0
  #7
Mar 15th, 2007
  1. input = stdin.readLine();

does return string and you are looking for integer. Does it help :cheesy: ?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Re: Probably an obvious mistake

 
0
  #8
Mar 16th, 2007
Sorry, I should have put the code above in. Its converted to an integer from the inputted string. Still a mystery!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Probably an obvious mistake

 
0
  #9
Mar 16th, 2007
Look at this from your code:
  1. try { //Reads keyboard input and acts accordingly
  2. input = stdin.readLine();
  3. }catch (IOException ex) {
  4. System.out.println("Problem reading from the keyboard");
  5.  
  6. iInput = Integer.valueOf(input); // convert String to Integer
  7. }

You convert your string input to an integer only when an exception happens. You need to move the closing brace from the catch block to a point before the iInput = line.

And, as a matter of fact, your indenting implies this to the reader, but the braces define something else, and it's the braces that count.
Last edited by masijade; Mar 16th, 2007 at 5:01 am. Reason: typo
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 69
Reputation: san_fran_crisko is an unknown quantity at this point 
Solved Threads: 0
san_fran_crisko san_fran_crisko is offline Offline
Junior Poster in Training

Re: Probably an obvious mistake

 
0
  #10
Mar 16th, 2007
Thanks masijade. I'll try that out when I get home from work.

Very much appreciated.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2216 | Replies: 16
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC