0

I am trying to implement a save and load feature for a library application, which stores technical manuals.

Ideally I would like the application to save the manuals in the library to a text file, and then load them back into the library whenever the user wants.

Currently I have this code to save and load the text file:

//Choice 7: Load Library:

            if(Menu.menuChoice == 7){
                boolean loadYesNo = Console.readYesNo("\n\nThe manualKeeper app is able to load and display any 'Library.txt' files \nfound in your home folder directory.\n\nWould you like to load and display library? (Y/N):\n");
                String fileName = "Library.txt";
                String line;
                if(loadYesNo){
                try {
                    BufferedReader input = new BufferedReader (new FileReader (fileName));
                    if (!input.ready()) {
                        throw new IOException();
                    }
                    while ((line = input.readLine()) != null) {
                        Library.ManualList.add(line);
                    }
                    input.close();
                } catch (IOException e) {
                    System.out.println(e);
                }

                Menu.displayMenu();

                } else if(!loadYesNo){
                    System.out.println("\n\n--------------------------------------------------------------------------");
                    System.out.println("\n                             Library not loaded!\n");
                    System.out.println("--------------------------------------------------------------------------\n");
                    Menu.displayMenu();
                }
            }


//Choice 0: Exit the program:

            if(Menu.menuChoice == 0){
                if(Menu.menuChoice == 0){
                    if(Library.ManualList.size() > 0){
                        boolean saveYesNo = Console.readYesNo("\nThe manualKeeper app is able to save your current library to a '.txt' \nfile in your home folder directory (C:\\Users\\ 'YOUR NAME').\n\nWould you like to save the current library? (Y/N):\n");
                        File fileName = new File ("Library.txt");
                        if(saveYesNo==true){
                            try {
                                FileWriter fw = new FileWriter(fileName);
                                Writer output = new BufferedWriter(fw);
                                for (int i = 0; i < Library.ManualList.size(); i++){
                                    output.write(Library.ManualList.get(i).displayManual() + "\n");
                                }
                                output.close();
                            } catch (Exception e) {
                                JOptionPane.showMessageDialog(null, "I cannot create that file!");
                                }
                        }
                            else if(saveYesNo==false){
                                System.out.println("\n\n--------------------------------------------------------------------------");
                                System.out.println("\n                              Library not saved!\n");
                                System.out.println("--------------------------------------------------------------------------\n");
                                break exit;
                        }
                        Menu.displayMenu();
                    }else if(Library.ManualList.isEmpty()){ 
                        Menu.displayMenu();
                    }
                }
            }               

        }
    System.out.println("\n              ~   You have exited the manualKeeper app!   ~                  ");
    System.out.println("\n                  Developed by Oscar - 2014 - UWL\n");
    System.out.println("\n                                   <3\n");

}
} 

When trying to run this I get the following errors:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
ManualList cannot be resolved

at library.Manual.run(Manual.java:139)
at library.startLibrary.main(startLibrary.java:11)
Travis Pettry
  • 1,220
  • 1
  • 14
  • 35
Oscar
  • 511
  • 2
  • 10
  • 25
  • How are you importing the `Library` class? Hint: It's not correctly – Kon Jan 08 '15 at 21:56
  • @Kon how can I do this correctly? Thanks for your reply – Oscar Jan 08 '15 at 21:57
  • Add the JAR that contains this class to your classpath, then import it. – Kon Jan 08 '15 at 21:58
  • @JamesPatterson nevermind what Kon said, the compiler is resolving `Library` fine - however, you are referencing a Library member by the name of `ManualList`, which does not exist. Check your capitalization, perhaps you meant to write `manualList`. – gknicker Jan 08 '15 at 22:11
  • Hint: fix the compilation errors **before** you attempt to run the code. – Stephen C Jan 08 '15 at 22:33
  • I meant capital M but I need to change it at a later date I know, manuallist is an array, would showing more of my code help? @StephenC & gknicker – Oscar Jan 08 '15 at 22:54
  • The duplicate question answers this one. The exception is caused by an unresolved compilation error, and the fix is to resolve the compilation error! We can't help you with the compilation error because you did not include the imports (for this class) and the declaration (in the Manual class) of the ManualList (sic) field. But that is a different question ... and you should create a new Question to ask it. – Stephen C Jan 09 '15 at 03:14
  • And please in future ask the question about the compilation error, and not the exception you get when you spuriously try to run code with compilation errors! – Stephen C Jan 09 '15 at 03:17

0 Answers0