Results 1 to 2 of 2

Thread: problems printing an arraylist

  1. #1

    Thread Starter
    Lively Member fundean's Avatar
    Join Date
    Apr 2001
    Posts
    98

    problems printing an arraylist

    // FOLLOWING GIVES ME A NULL POINTER EXCEPTION --- ANY HELP
    // GREATLY APPRECIATED

    import java.util.ArrayList;
    public class Example
    {
    public static ArrayList<Integer> nums;
    public static void numQuest()
    {
    int k = 0;
    Integer zero = new Integer(0);

    nums.add(0);
    nums.add(0);
    nums.add(4);
    nums.add(2);
    nums.add(5);
    nums.add(0);
    nums.add(3);
    nums.add(0);
    while ( k < nums.size())
    {
    if (nums.get(k).equals(zero))
    nums.remove(k);
    k++;
    }
    System.out.print("contents of nums: " + nums );
    System.out.print("\n");
    }



    public static void main (String[] args)
    {

    numQuest();

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: problems printing an arraylist

    You need to initialize your arraylist.

    Code:
    public static ArrayList<Integer> nums = new ArrayList<Integer>();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width