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?????
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?????
Comment