0

just been trying to convert a string into an Integer so that I can use it for something else but I keep falling into the null pointer exception trap.

public class ConvertToInt {
private InputReader reader;

public int changeToInteger(String word){

// Problem i've got is just below, I keep getting a null point exception on this line each time     
// I want to return the result.

       return reader.convertToInt(word); // null ponter exception on this line
    }
}

parseInt method from InputReader class:

/**
 * Convert the given word to an integer.
 * @param word The word to be converted.
 * @return The integer represented by word.
 * @throws NumberFormatException if word is not an integer.
 */
public int convertToInt(String word)
{
    return Integer.parseInt(word);
}
Charles
  • 1
  • 1

0 Answers0