File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes adding a Double value to a list Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "adding a Double value to a list" Watch "adding a Double value to a list" New topic
Author

adding a Double value to a list

Ram Bu
Greenhorn

Joined: Jul 15, 2005
Posts: 13
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://jrebel.com/download
 
subject: adding a Double value to a list
 
Similar Threads
data-type mismatch
meaning of double angle brackets(<< >>) in Generics?
upper bound wildcard is readonly but lower bound are not
Wrapper class
Use of abs() method