   Null pointer problem
  Ok, I am writing a Finite State Machine program and it''s all but done except for this stupid null pointer exception that I cannot track down. Here''s the code:Machine.java   /** * Machine.java * @author Cory Swanson * @version 1.0 * * This class defines the Finite State Machine and * controls the running of such. */import java.util.*;import java.io.*;public class Machine{private static StringTokenizer tokenizer;private static String machineOutput;private static BufferedReader fin;private static State currentState;private static State[] stateArray;private static String alphabet;private static int numStates, numAlpha;public static String runMachine(String filename, String input){initMachine(filename);makeMachine();return doItMan(input);}public static BufferedReader openFileForReading(String filename){BufferedReader in=null;try{in = new BufferedReader(new FileReader(filename));}catch(FileNotFoundException e){System.out.println("Error: File " + filename + " not found, nimrod!");System.exit(1);}return in;}public static String readLineFromFile(BufferedReader r){String line="";try{line=r.readLine();}catch(IOException e){System.out.println("Your file sucks -- unable to read a line.");System.exit(1);}return line;}public static int readIntFromFile(BufferedReader r){int num=0;try{num=r.read();}catch(IOException e){System.out.println("Your file sucks -- unable to read an int.");System.exit(1);}return num;}public static void initMachine(String filename){fin = openFileForReading(filename);numStates = readIntFromFile(fin);numAlpha = readIntFromFile(fin);alphabet = readLineFromFile(fin);stateArray = new State[numStates];for(int i=0; i<stateArray.length; i++){stateArray = new State(i);}currentState = stateArray[0];}public static void makeMachine(){int nextState;String temp;for(int i=0; i&lt;stateArray.length; i++){for(int j=0; j&lt;alphabet.length(); j++){nextState = readIntFromFile(fin);stateArray.createTransition(alphabet.charAt(j), stateArray);}}String output = "</font><font color=darkred>";for(int i=0; i&lt;stateArray.length; i++){for(int j=0; j&lt;alphabet.length(); j++){temp = readLineFromFile(fin);tokenizer = new StringTokenizer(temp);output = tokenizer.nextToken("</font>\"<font color=darkred>") + "</font> <font color=darkred>";stateArray.setOutput(alphabet.charAt(j), output);if(tokenizer.hasMoreTokens()) tokenizer.nextToken("</font>\"<font color=darkred>");}}}public static String doItMan(String input){String finalOutput = "</font><font color=darkred>";for(int i=0; i&lt;input.length(); i++){finalOutput += currentState.getOutput(input.charAt(i));currentState = (currentState.getTransition(input.charAt(i))).getState();}return finalOutput;}public static void main(String[] args){String filename = args[0];String results = runMachine(filename, "</font>QQCDNQNDTQDDQNCCTDNQDCTQQNNDDDC");System.out.println(results);}}</pre><!–ENDSCRIPT–>State.java   <!–STARTSCRIPT–><pre class="source"><font color=gray>/** * State.java * @author Cory Swanson * @version 1.0 * * This class defines a State object for use in a Finite * State Machine. */</font>import java.util.*;<font color=blue>public</font> <font color=blue>class</font> State{<font color=blue>private</font> Hashtable transitionTable;<font color=blue>private</font> Hashtable outputs;<font color=blue>private</font> <font color=blue>int</font> stateNum;<font color=blue>public</font> State(<font color=blue>int</font> stateNum){<font color=blue>this</font>.stateNum = stateNum;transitionTable = <font color=blue>new</font> Hashtable();outputs = <font color=blue>new</font> Hashtable();}<font color=blue>public</font> <font color=blue>int</font> getStateNum(){<font color=blue>return</font> stateNum;}<font color=blue>public</font> Transition createTransition(<font color=blue>char</font> c, State s){<font color=blue>return</font> <font color=blue>new</font> Transition(c, s);}<font color=blue>public</font> <font color=blue>void</font> setTransition(<font color=blue>char</font> c, Transition t){String key=c+"<font color=darkred>";transitionTable.put(key, t);}public Transition getTransition(char c){String key=c+"</font><font color=darkred>";return (Transition)transitionTable.get(key);}public void setOutput(char c, String s){String key=c+"</font><font color=darkred>";outputs.put(key, s);}public String getOutput(char c){String key=c+"</font>";<font color=blue>return</font> (String)outputs.get(key);}}</pre><!–ENDSCRIPT–>Transition.java   <!–STARTSCRIPT–><pre class="source"><font color=blue>public</font> <font color=blue>class</font> Transition{<font color=blue>private</font> String output;<font color=blue>private</font> State state;<font color=blue>private</font> <font color=blue>char</font> alpha;<font color=blue>public</font> Transition(<font color=blue>char</font> c, State s){alpha = c;state = s;}<font color=blue>public</font> State getState(){<font color=blue>return</font> state;}<font color=blue>public</font> <font color=blue>void</font> setOutput(String s){output = s;}<font color=blue>public</font> String getOutput(){<font color=blue>return</font> <font color=blue>this</font>.output;}}</pre><!–ENDSCRIPT–>Here''s the text file which defines the FSM:   <!–STARTSCRIPT–><pre class="source">95NDQTC1 2 5 0 02 3 6 0 03 4 2 0 04 5 3 0 05 6 4 7 06 5 5 7 86 6 6 7 81 2 5 7 71 2 5 8 8<font color=darkred><font color=darkred><font color=darkred>"$0.05"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred>"$0.10"</font></font></font></font> <font color=darkred><font color=darkred>"$0.25"</font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"$0.10"</font></font></font></font> <font color=darkred><font color=darkred>"$0.15"</font></font> <font color=darkred><font color=darkred><font color=darkred>"$0.30"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred>"$0.15"</font></font> <font color=darkred><font color=darkred>"$0.20"</font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Quarter"</font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred>"$0.20"</font></font> <font color=darkred><font color=darkred><font color=darkred>"$0.30"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Quarter"</font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred>"$0.25"</font></font> <font color=darkred><font color=darkred><font color=darkred>"Dime"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Quarter"</font></font></font></font></font> <font color=darkred>"Tea"</font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred><font color=darkred>"$0.30"</font></font></font> <font color=darkred><font color=darkred><font color=darkred>"Dime"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Quarter"</font></font></font></font></font> <font color=darkred>"Tea and Nickel"</font> <font color=darkred>"Coffee"</font><font color=darkred>"Nickel"</font> <font color=darkred><font color=darkred><font color=darkred>"Dime"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Quarter"</font></font></font></font></font> <font color=darkred>"Tea and Dime"</font> <font color=darkred>"Coffee and Nickel"</font><font color=darkred><font color=darkred><font color=darkred>"$0.05"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred>"$0.10"</font></font></font></font> <font color=darkred><font color=darkred>"0.25"</font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font><font color=darkred><font color=darkred><font color=darkred>"$0.05"</font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred>"$0.10"</font></font></font></font> <font color=darkred><font color=darkred>"0.25"</font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font> <font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred><font color=darkred>"Buuzzzzzaaap!"</font></font></font></font></font></font></font></font></font></font></font></font></font></pre><!–ENDSCRIPT–>Any ideas? I''m getting a null pointer in the main method but can''t locate it at all!! ARGH!Thanks in advance!   
  Doesn''t the debugger tell you exactly what file and line the exception occurs at? ;  Are you giving it some command line arguments?   EDIT: And please post the exact error message from your VM.Human beings, by changing the inner attitudes of their minds, can change the outer aspects of their lives.William James (1842 - 1910)  [edited by - rohde on December 16, 2003 8:03:35 PM];  Actually, I figured it out. The hashtable was not getting filled correctly. 