Results 1 to 3 of 3

Thread: [RESOLVED]HELP!!BitSet set() returns null...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Resolved [RESOLVED]HELP!!BitSet set() returns null...

    Does anyone knows why my fingerprint2 is null when I print it out? Here is my code:
    Code:
     try
    {
            FileInputStream input = new FileInputStream ("fp.bin");
            DataInputStream binData = new DataInputStream (input);
    	
            BitSet fingerprint2 = new BitSet[3]; //my fp.bin file only consists of 2 binaries
            for(int i=0;i<3;i++)
            {
    		for(int j=0;j<1024;j++)
    		{
    			boolean bit = binData.readBoolean();
    			fingerprint2[i].set(j,bit); //something wrong here?
    		}
    		System.out.println(fingerprint2[i]); //throw NullPointerException
    	}
    	binData.close();
    	input.close();
    }
    catch(EOFException eof)
    {
    	
    }
    catch(NullPointerException npe)
    {
    	System.out.println("Null Pointer");
    }
    catch (FileNotFoundException fe)
    {
    	System.out.println("No such file.");
    }
    catch (IOException ie)
    {
    	System.out.println(ie.toString());
    }
    Last edited by huiling25; Jan 19th, 2007 at 02:20 AM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Red face Re: [RESOLVED]HELP!!BitSet set() returns null...

    I have found a solution for this problem. Here is the code:
    Code:
    BitSet[] fingerprint2 = new BitSet[3];
    for(int i=0;i<3;i++)
    {
    	fingerprint2[i] = new BitSet(); //have to initialise fingerprint2 first
    	for(int j=0;j<1024;j++)
    	{
    		boolean bit = binData.readBoolean();	
    		fingerprint2[i].set(j,bit);
    	}
    	System.out.println(fingerprint2[i]);
    }

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: [RESOLVED]HELP!!BitSet set() returns null...

    When you allocate an array, the individual members are initialized to their default values. In the case of object references, that's null. You have to allocate each array member individually.


    Which is exactly the solution you came up with.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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