HELP!!BitSet set() returns null..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • huiling25
    New Member
    • Dec 2006
    • 35

    #1

    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());
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by huiling25
    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());
    }
    From a quick look I'd say, try so that you initialize the array first

    Code:
    BitSet fingerprint2 = new BitSet[3]; 
    for(int i = 0; i < fingerprint2.length;i++ ) {
       fingerprint2[i] = new BitSet();
    }
    ....
    ..
    because the line
    Code:
    fingerprint2[i].set(j,bit);
    is the one throwing a null pointer exception

    Comment

    • huiling25
      New Member
      • Dec 2006
      • 35

      #3
      Originally posted by r035198x
      From a quick look I'd say, try so that you initialize the array first

      Code:
      BitSet fingerprint2 = new BitSet[3]; 
      for(int i = 0; i < fingerprint2.length;i++ ) {
         fingerprint2[i] = new BitSet();
      }
      ....
      ..
      because the line
      Code:
      fingerprint2[i].set(j,bit);
      is the one throwing a null pointer exception
      I tried your suggestion, but nothing was printed out. Here is how i put it:
      Code:
      BitSet fingerprint2 = new BitSet[3]; 
      for(int i=0;i<counter;i++)
      {
      	fingerprint2[i] = new BitSet();
      	for(int j=0;j<1024;j++)
      	{
      		boolean bit = binData.readBoolean();	
      		fingerprint2[i].set(j,bit);		 
      	}
      	System.out.println(fingerprint2[i]);	//nothing was printed out
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by huiling25
        I tried your suggestion, but nothing was printed out. Here is how i put it:
        Code:
        BitSet fingerprint2 = new BitSet[3]; 
        for(int i=0;i<counter;i++)
        {
        	fingerprint2[i] = new BitSet();
        	for(int j=0;j<1024;j++)
        	{
        		boolean bit = binData.readBoolean();	
        		fingerprint2[i].set(j,bit);		 
        	}
        	System.out.println(fingerprint2[i]);	//nothing was printed out
        }
        Then you are definitely getting an EndOfFileExcept ion.

        Change your catch statements from
        Code:
        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());
        }
        to


        Code:
        catch(EOFException eof)
        {
        	System.out.println("End of File Exception");
        }
        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());
        }
        And see if this isn't true.

        Comment

        • huiling25
          New Member
          • Dec 2006
          • 35

          #5
          Originally posted by r035198x
          Then you are definitely getting an EndOfFileExcept ion.

          Change your catch statements from
          Code:
          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());
          }
          to


          Code:
          catch(EOFException eof)
          {
          	System.out.println("End of File Exception");
          }
          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());
          }
          And see if this isn't true.
          Thanks, it work out already. =)

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by huiling25
            Thanks, it work out already. =)
            What did you do then?

            Comment

            Working...