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)
8
  • How are you importing the Library class? Hint: It's not correctly Commented Jan 8, 2015 at 21:56
  • @Kon how can I do this correctly? Thanks for your reply Commented Jan 8, 2015 at 21:57
  • Add the JAR that contains this class to your classpath, then import it. Commented Jan 8, 2015 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. Commented Jan 8, 2015 at 22:11
  • Hint: fix the compilation errors before you attempt to run the code. Commented Jan 8, 2015 at 22:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.