I'm trying to read a file and set each line from the file as the parameters to the object OS_Process that I made, then place those processes in a linklist queue. However, I keep getting a nullpointerexception. The data file looks as follows. Every new process data is on a new line.
3 //counter
1 3 6 //process 1 data
3 2 6 //process 2 data
4 3 7 //process 3 data
And this is my code
import java.io.*;
import java.util.*;
public class OS_Scheduler
{
public static void main(String[] args)
{
Queue<OS_Process> jobs = new LinkedList<OS_Process>();
try
{
System.out.print("Enter the file name: ");
Scanner file = new Scanner(System.in);
File filename = new File(file.nextLine());
OS_Process proc = null;
String s = null;
int a = 0, p = 0, b = 0;
BufferedReader input = new BufferedReader(new FileReader(filename));
StringTokenizer st = new StringTokenizer(s);
int count = Integer.parseInt(st.nextToken());
while ((s = input.readLine()) != null)
{
st = new StringTokenizer(s);
a = Integer.parseInt(st.nextToken());
p = Integer.parseInt(st.nextToken());
b = Integer.parseInt(st.nextToken());
proc = new OS_Process(a, p, b, 0);
jobs.add(proc);
}
input.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}