By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,779 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,779 IT Pros & Developers. It's quick & easy.


P: 1
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)
running a test program I get an error java.lang.NullPointerException
pointing at the line

what's wrong with my code?????
Nov 20 '06 #1
Share this Question
Share on Google+
2 Replies

Expert 2.5K+
P: 3,652
Did you forget to initialize n to 0 in your constructor?
Nov 20 '06 #2

Expert 100+
P: 1,510
very odd - one would assume from the error message that reference value[] is null - if n was out of bounds you would get an outOfBoundsException - I suggest you print the values of n and value[] when you enter the function adauga()
Nov 21 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.