Hi there, when calling a method from another class I get the following error message:
**
Exception in thread "main" java.lang.NullPointerException
at TextAnalyser.main(TextAnalyser.java:23)
**
My two classes:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String.*;
import java.util.*;
public class TextAnalyser {
static Tokeniser aTokeniser;
public TextAnalyser(Tokeniser aTokeniser) {
}
public static void main( String args[] )
{
int sentence;
Scanner scanner = new Scanner( System.in );
System.out.println( "Type 1 and press Enter" );
sentence = Integer.parseInt(scanner.nextLine());
if(sentence == 1) {
aTokeniser.add();
aTokeniser.print();
}
}
}//end
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
public class Tokeniser {
StringTokenizer aToken;
ArrayList words = new ArrayList();
public Tokeniser(StringTokenizer aToken) {
aToken = new StringTokenizer("You are Tokenizing a String");
}
public void add() {
System.out.println("The total no. of tokens generated : " + aToken.countTokens());
while(aToken.hasMoreTokens()){
words.add(aToken.nextToken());
}
}
Line 23 is : aTokeniser.add();
so it obviously doesn't like what i'm pointing too, I'm thinking maybe that i need to define a return type? im not sure if ive used the constructors correctly.