| | |
Probably an obvious mistake
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2006
Posts: 69
Reputation:
Solved Threads: 0
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.
Anyone who could shed light on the issue, it would be greatly appreciated.
Thanks.
Java Syntax (Toggle Plain Text)
import java.io.*; //import API to allow input of characters import java.util.Vector; //import API to allow Vector functionality class Details { String name = null; String artist = null; String year = null; String genre = null; String rating = null; Vector v = new Vector(); public void newcd() { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println("CD Name: "); try { //Reads keyboard input and acts accordingly name = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); } System.out.println("Artist: "); try { //Reads keyboard input and acts accordingly artist = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); } System.out.println("Year of album: "); try { //Reads keyboard input and acts accordingly year = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); } System.out.println("Genre: "); try { //Reads keyboard input and acts accordingly genre = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); } System.out.println("Rating: "); try { //Reads keyboard input and acts accordingly rating = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); } Details disc = new Details (); disc.name = name; disc.artist = artist; disc.year = year; disc.genre = genre; disc.rating = rating; v.add(disc); } } public class CDSystem { //main class public static void main (String [] args) { //main method containing menu system String input = null; //initialising input string int iInput; int ixInput; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Welcome to your CD Collection"); //commands to display menu on screen System.out.println("Select an option from the menu:"); System.out.println("1: Add a new CD"); System.out.println("2: Display CDs by artist"); System.out.println("3: Display CDs by genre"); System.out.println("4: Display all albums ascending by year"); System.out.println("5: Display all albums descending by rating"); System.out.println("Press any other key to exit"); try { //Reads keyboard input and acts accordingly input = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); iInput = Integer.valueOf(input); // convert String to Integer } if (iInput == 1) { newcd(); } if (iInput == 2) { artistdisplay(); } if (iInput == 3) { genredisplay(); } if (iInput == 4) { yeardisplay(); } if (iInput == 5) { ratingdisplay(); } else { System.out.println("Thank you for using CDSystem"); } } }
•
•
•
•
Java Syntax (Toggle Plain Text)
if (iInput == 1) { newcd(); } if (iInput == 2) { artistdisplay(); } if (iInput == 3) { genredisplay(); } if (iInput == 4) { yeardisplay(); } if (iInput == 5) { ratingdisplay(); } else { System.out.println("Thank you for using CDSystem"); } } }
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
Java Syntax (Toggle Plain Text)
SecondClass secondClass = new SecondClass(); if (iInput == 1) { secondClass.newcd(); }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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.
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
•
•
Join Date: Nov 2006
Posts: 69
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2006
Posts: 69
Reputation:
Solved Threads: 0
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.
System.out.println("Thank you for using CDSystem");

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.
Java Syntax (Toggle Plain Text)
if (iInput == 1) { newcd(); } if (iInput == 2) { artistdisplay(); } if (iInput == 3) { genredisplay(); } if (iInput == 4) { yeardisplay(); } if (iInput == 5) { ratingdisplay(); } else {
Java Syntax (Toggle Plain Text)
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Look at this from your code:
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
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.
Java Syntax (Toggle Plain Text)
try { //Reads keyboard input and acts accordingly input = stdin.readLine(); }catch (IOException ex) { System.out.println("Problem reading from the keyboard"); iInput = Integer.valueOf(input); // convert String to Integer }
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
----------------------------------------------
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
![]() |
Similar Threads
- Parse error: syntax error, unexpected T_STRING (PHP)
- If Else If Help plz (C++)
- Python GUI build: Logic Complications and Mistakes (Python)
- The Logic of This Code is Skewed Perhaps: (C++)
Other Threads in the Java Forum
- Previous Thread: card game
- Next Thread: Unknown problem with either storing/recalling information from a Vector
Views: 2216 | Replies: 16
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited webservices windows






