Java program static menu method cant call non static variables?
-
here is a sample of my source code my teacher wants us to have a a bunch of static/non static methods called and through a menu method but i keep getting the error that non static variables adn methods can not be referenced from a static content is there any way around this as well as non of my methods execute from the menu when i run the file it just shows the menu on the console does nothing when i enter a number any ideas public static void showMenu() { Scanner input=new Scanner(System.in); System.out.println("1: Forward \n" + "2: Bacward \n3: Forward G\n" + "4: Bacward G \n" + "5: Create File name \n" + "6: Create Random file name\n" + "7: Show Window\n" + "8: Exit \n" + "Select option:" ); do{ boolean quit = false; int SwitchValue =input.nextInt(); switch (SwitchValue) { case 1: { image_number = Forward(image_number); System.out.println(image_number); break; } case 2: { image_number = Backward(image_number); break; } case 3:{ Forward(image_number); break; } case 4:{ Backward(image_number); break; } case 5:{ CreateFilename(image_number); break; } case 6:{ CreateRandomName(); break; } case 7:{ showWindow(filename); break; } case 8: { getImage(); break; } case 9: { quit= true; break; } default: System.err.println ( "Unrecognized option" ); } }while(!true); } public static void main(String[] args) { Project3 object= new Project3(); Project3.showMenu(); } } and here is a sample of my methods public static int Forward(int current_number) { if( current_number >= MAX_NUMBER){ current_number = 1; } else { current_number ++; } return current_number; } public void Forward() { if (image_number >= MAX_NUMBER){ image_number = MIN_NUMBER; } else image_number ++; } public static int Backward(int current_number) { if (current_number <= MIN_NUMBER && current_number >= MAX_NUMBER){ current_number --; } else current_number = 1; return current_number; }
-
Answer:
so how are you building this? Are you using eclipse or Netbeans or some other ide or are you using cli and javac? Have you figured out how to get the information from the error console to help figure out where the error is occurring? Usually it is referenced with a line number so that should help you figure out where the problem is. I couldn't find a problem with your code compiling it. of course I had to comment out your undocumented functions such as CreateFilename(int). Maybe if you provide more information we can get to the root of the matter. Oh and if you haven't done so, do a clean and then rebuild if you're using an IDE.
chris at Yahoo! Answers Visit the source
Other answers
Where is image_number defined? +add At least copy & paste the error message.
Related Q & A:
- What do we call the "middle" variables in a complex research model?Best solution by Cognitive Sciences
- How to access a non static method in an abstract class's static method?Best solution by Stack Overflow
- Why cannot we use static keyword inside a method in java?Best solution by Stack Overflow
- How to get actual return type of a generic static method in Java?Best solution by stackoverflow.com
- How to create this Java program?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.