Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The program is quite poorly written. Look at this in your FoundationsOfComputing.java:</p> <pre><code> state0 = new DFA_State(); state1 = new DFA_State(); state0 = new DFA_State("State 0",true, state0, state1); </code></pre> <p>You essentially created 3 instances of state - two instances which are not initialized (first two lines in your code) - all their instance variables are null.</p> <p>Then you create the third instance, which you point to the first two uninitialized ones, and assign it to state0 variable. Please note, at this point, it is only the value of the variable that changes, not the values you passed in the DFA-State constructor!!! So, what you now have in state0 is a state that points to two uninitialized states.</p> <p>Now let's look at the code further down in the FoundationsOfComputing.java:</p> <pre><code> while (i &lt; arr1.length) {//loops through array System.out.println(i + ". scan shows " + arr1[i]); temp = new DFA_State(curr_state.nextState(arr1[i])); System.out.println(" "+curr_state.get_name()+ " moves onto " + temp.get_name()); curr_state = new DFA_State(temp); i++; } </code></pre> <p>I am guessing this throws NullPointerException - that code moves to the on_0 state of state0 - which is a state that has not been initialized (all it's instance variables are null), so in the following pass of the loop, when it calls curr_state.nextState(whatever), it would return null and you are trying to pass that to the copy-constructor which would result in NPE.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload