Help!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andifcb
    New Member
    • Nov 2006
    • 1

    #1

    Help!!!!

    I'm new to Java and I encountered the following problem:
    i wanted to create one array of Comparable elements and one array of strings:\
    i created them using

    class dictionary{
    private Comparable value[]=new Comparable[25];
    private String key[]=new String[25];
    private int n;

    in a public method i wanted to modify the elements of the two strings:

    public void adauga(String x, Comparable v)
    {
    key[n]=x;
    value[n]=v;
    n++;
    }
    running a test program I get an error java.lang.NullP ointerException
    pointing at the line
    value[n]=v;

    what's wrong with my code?????
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Did you forget to initialize n to 0 in your constructor?

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      very odd - one would assume from the error message that reference value[] is null - if n was out of bounds you would get an outOfBoundsExce ption - I suggest you print the values of n and value[] when you enter the function adauga()

      Comment

      Working...