• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding a Double value to a list  RSS feed

 
Ram Bu
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following code is throwing a NullPointerException

import java.util.List;
public class Test {

public static void main(String[] args) {

List l = null;
double d = 2386870.0;
l.add(new Double(d));

}
}

Can someone shed some light on why this is happening and how to fix it.

Thank you.
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A list is an object in java and all lists must be created. When you declare a list such as:



you only created a pointer to a list, not the list itself. In this case, you create a pointer to a list l, and assign it a value of null. You must assign the pointer the value of a real list in order to use the list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!