When run if there is a file it will give a no such element exception on head.setId(), and yes it is a school project but i can't figure out a way to correct it.
file contains this:
1
dude
1
is tall
50.0
:
import java.util.Scanner;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
public class InvManagerll
{
int count;
itemnode head = new itemnode();
public InvManagerll()
{
count = 1;
return;
}
void Save()
{
itemnode I;
I = head;
PrintWriter outputStream = null;
try
{
outputStream = new PrintWriter(new FileOutputStream("Inventory.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("Error opening the file Inventory.txt.");
}
if (outputStream != null)
{
System.out.println("Saving inventory data to Inventory.text.");
while (I != null)
{
outputStream.println(I.GetId());
outputStream.println(I.getName());
outputStream.println(I.getStock());
outputStream.println(I.getdescrip());
outputStream.println(I.getUP());
I = I.getnext();
}
outputStream.close();
}
}
void Load()
{
itemnode I;
System.out.println("Loading Inventory.txt file for current inventory");
Scanner inputStream = null;
try
{
inputStream = new Scanner(new FileInputStream("Inventory.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("the file was not found or could not be opened");
}
if (inputStream != null)
{
while ((inputStream.hasNextLine()))
{
I = head.getnext();
head = new itemnode();
head.setId(inputStream.nextInt());
inputStream.nextLine();
head.SetName(inputStream.nextLine());
head.SetStock(inputStream.nextInt());
inputStream.nextLine();
head.setdesrip(inputStream.nextLine());
head.SetUP(inputStream.nextDouble());
head.setnext(I);
}
inputStream.close();
}
}
}