I'm reading in a file and I need to skip any lines of length zero or starting with '#'. But I keep getting null pointer exceptions later in the code because it can never tokenize. What am I doing wrong? Thanks in advance.
Below is the relevant method:
static void readSrc(String fname) throws IOException
{
String buffer = null;
String line;
int token = 0;
FileReader fr = new FileReader(fname);
BufferedReader br = new BufferedReader(fr);
while ((buffer = br.readLine()) !=null){
for (int i=0; i<27;i++)
{
if (buffer.equals(null)){buffer = br.readLine();i++;}
else if (buffer.substring(0,1).equals("#")){buffer = br.readLine();i++;}
else{ // tokenize string. 1st token is opcode, 2nd is operand
StringTokenizer st = new StringTokenizer(buffer," ");
token = st.countTokens();
if (st.hasMoreTokens()){
source[i][(0)] = (st.nextToken());
source[i][(1)] = (st.nextToken());
}
buffer = br.readLine();
}
}
}
}