I have the following function in a class named cache_level which extends the linked list class.:
@SuppressWarnings("unchecked")
public boolean addObject(Object O)
{
System.out.println(O);
if(O != null)
{
boolean x = getObject(O);
int I = 21;
if(x == true && size() == cacheSize) //if object is found and size of list is full
{
remove(O);
addFirst(I);
cacheHit++; //increment to show we found the object
}
else if(x == true && size() != cacheSize)//found but not full
{
addFirst(I);
cacheHit++;
}
else if(x != true && size() == cacheSize) //item not found but list full
{
removeLast();
addFirst(I);
}
else //item not found and list not full
{
addFirst(I);
}
return x;
}
else
{
System.out.println("NULL OBJECT WAS FOUND");
return false;
}
}
and I have a function in main which uses a scanner to read a text file.:
File file = new File(filename);
Scanner fileScan = new Scanner(file);
String line = "";
String token = "&";
while ((fileScan.hasNextLine()))
{
line = fileScan.nextLine();
Scanner lineScan = new Scanner(line);
//System.out.println(token);
while (lineScan.hasNext())
{
token = lineScan.next();
//System.out.println(token);
List.cacheAdd(token); //goes to cache class and initiallizes
//System.out.println(token);
}
lineScan.close();
}
//System.out.println("CACHE WAS CREATED");
fileScan.close();
and for some reason that is giving me a NullPointerException
and so far everyone I have talked to has no idea why that is happening. I have a class named Cache
, which initializes cache_level
. Reading the text file seems to be okay as I can print out the contents being stored into token but whenever I try to add it into the list, it gives me an error.