Note that there are some explanatory texts on larger screens.

plurals
  1. POi have an inventory program, and it wont load my results
    text
    copied!<p>i have this inventory program, but i cant get the information to load. I'm pretty new to programming. i think its either the for loop in the load method. or it could be the myinven[I] = new Item(iID); in the load method.</p> <pre><code>public class Inventory { int count = 0; int max = 4; Item[] myinven = new Item[max]; Scanner input = new Scanner(System.in); public void save() { PrintWriter outputStream = null; try { outputStream = new PrintWriter(new FileOutputStream("Inventory.txt")); } catch (FileNotFoundException e) { System.out.println("Error opening the file"); } for (int I = 0; I &lt;= count - 1; I++) if (outputStream != null) { outputStream.println(myinven[I].getID()); outputStream.println(myinven[I].getname()); outputStream.println(myinven[I].getdescription()); outputStream.println(myinven[I].getonhand()); outputStream.println(myinven[I].getunitprice()); outputStream.close(); } } public void load() { Scanner inputStream = null; try { inputStream = new Scanner(new FileInputStream("Inventory.txt")); } catch (FileNotFoundException e) { System.out.println("The File was not found"); } for (int I = 0; I &lt;= count - 1; I++) { if (inputStream != null) { while (inputStream.hasNext()) { myinven[I] = new Item(inputStream.nextInt()); myinven[I].setname(inputStream.nextLine()); myinven[I].setdescription(inputStream.nextLine()); myinven[I].setonhand(inputStream.nextInt()); myinven[I].setunitprice(inputStream.nextDouble()); inputStream.close(); } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload