i have a function that is supposed to check a string against a set of types, stored as a hash set in the class o.
however the function only works if there is one word. if the string conmtains more than 2 words, my program crashes with NullPointerException.
public static boolean checkOpcode(String opcode)
{
StringTokenizer st = new StringTokenizer(opcode);
String[] basics = new String[st.countTokens()];
for(int j = 0; j <= st.countTokens(); j++)
{
basics[j] = st.nextToken();
}
boolean[] ok = new boolean[basics.length];
boolean correct = false;
int t = 0;
if (opcode.indexOf("0X") > 0)
return true;
else
{
for(int i = 0; i < ok.length;)
{
if(basics[i].contains("$")) /* <----- error occurs here, regardless of if there is a $ or not */
{
ok[i] = true;
i++;
}
else if(o.ops.contains(basics[i]))
ok[i] = true;
else ok[i] = false;
i++;
}
for(boolean b : ok)
{
if(!b)
return false;
else t+=1;
}
}
if(t == basics.length)
correct = true;
return correct;
}
any ideas? i've tried String.split and that didn't work.