Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer Exception: null error
    primarykey
    data
    text
    <p>I have this Hash Set code and when I try to run my compile method on it I get the Null Pointer Exception: null error on it. Here is the code:</p> <pre><code>private void initKeywords() { keywords = new HashSet&lt;String&gt;(); keywords.add("final"); keywords.add("int"); keywords.add("while"); keywords.add("if"); keywords.add("else"); keywords.add("print"); } private boolean isIdent(String t) { if (keywords.contains(t)) { ***//This is the line I get the Error*** return false; } else if (t != null &amp;&amp; t.length() &gt; 0 &amp;&amp; Character.isLetter(t.charAt(0))) { return true; } else { return false; } } </code></pre> <p>The other lines that goes along with this error is: </p> <pre><code>public void compileProgram() { System.out.println("compiling " + filename); while (theToken != null) { if (equals(theToken, "int") || equals(theToken, "final")) { compileDeclaration(true); } else { compileFunction(); //This line is giving an error with the above error } } cs.emit(Machine.HALT); isCompiled = true; } private void compileFunction() { String fname = theToken; int entryPoint = cs.getPos(); if (equals(fname, "main")) { cs.setEntry(entryPoint); } if (isIdent(theToken)) theToken = t.token(); ***//This line is giving an error*** else t.error("expecting identifier, got " + theToken); symTable.allocProc(fname,entryPoint); accept("("); compileParamList(); accept(")"); compileCompound(true); if (equals(fname, "main")) cs.emit(Machine.HALT); else cs.emit(Machine.RET); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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