I have a piece of code where the program compares the value of two arrays of strings. I am getting a java.lang.NullPointerException, even though I initialized both arrays. Here is the relevant code:
String[] functions=new String [inputs+1];
int funCounter=0;
for (int a=0;a<2;a++)
{
for (int b=0;b<2;b++)
{
if (tokenizedString[b].equals(keywords[a])&&keywords[a].equals("add"))
{
System.out.println("Yay");
functions[funCounter]="add";
funCounter++;
}
}
}
This is where I inialize tokenizedString:
String[] tokenizedString;
tokenizedString=new String[2];
tokenizedString is added to a Scanner in stream here:
StringTokenizer st = new StringTokenizer(input," ");
And here is where I initialize keywords:
String[] keywords;
keywords=new String[2];
Any ideas? Thanks!
tokenizedString, but have you initializedtokenizedString[0]andtokenizedString[1]?keywords? Did you assign any values as elements oftokenizedString?