By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

HELP!!BitSet set() returns null..

P: 35
Does anyone knows why my fingerprint2 is null when I print it out? Here is my code:
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.         FileInputStream input = new FileInputStream ("fp.bin");
  4.         DataInputStream binData = new DataInputStream (input);
  5.  
  6.         BitSet fingerprint2 = new BitSet[3]; //my fp.bin file only consists of 2 binaries
  7.         for(int i=0;i<3;i++)
  8.         {
  9.         for(int j=0;j<1024;j++)
  10.         {
  11.             boolean bit = binData.readBoolean();
  12.             fingerprint2[i].set(j,bit); //something wrong here?
  13.         }
  14.         System.out.println(fingerprint2[i]); //throw NullPointerException
  15.     }
  16.     binData.close();
  17.     input.close();
  18. }
  19. catch(EOFException eof)
  20. {
  21.  
  22. }
  23. catch(NullPointerException npe)
  24. {
  25.     System.out.println("Null Pointer");
  26. }
  27. catch (FileNotFoundException fe)
  28. {
  29.     System.out.println("No such file.");
  30. }
  31. catch (IOException ie)
  32. {
  33.     System.out.println(ie.toString());
  34. }
Jan 19 '07 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
Does anyone knows why my fingerprint2 is null when I print it out? Here is my code:
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3.         FileInputStream input = new FileInputStream ("fp.bin");
  4.         DataInputStream binData = new DataInputStream (input);
  5.  
  6.         BitSet fingerprint2 = new BitSet[3]; //my fp.bin file only consists of 2 binaries
  7.         for(int i=0;i<3;i++)
  8.         {
  9.         for(int j=0;j<1024;j++)
  10.         {
  11.             boolean bit = binData.readBoolean();
  12.             fingerprint2[i].set(j,bit); //something wrong here?
  13.         }
  14.         System.out.println(fingerprint2[i]); //throw NullPointerException
  15.     }
  16.     binData.close();
  17.     input.close();
  18. }
  19. catch(EOFException eof)
  20. {
  21.  
  22. }
  23. catch(NullPointerException npe)
  24. {
  25.     System.out.println("Null Pointer");
  26. }
  27. catch (FileNotFoundException fe)
  28. {
  29.     System.out.println("No such file.");
  30. }
  31. catch (IOException ie)
  32. {
  33.     System.out.println(ie.toString());
  34. }
From a quick look I'd say, try so that you initialize the array first

Expand|Select|Wrap|Line Numbers
  1. BitSet fingerprint2 = new BitSet[3]; 
  2. for(int i = 0; i < fingerprint2.length;i++ ) {
  3.    fingerprint2[i] = new BitSet();
  4. }
  5. ....
  6. .. 
because the line
Expand|Select|Wrap|Line Numbers
  1. fingerprint2[i].set(j,bit); 
is the one throwing a null pointer exception
Jan 19 '07 #2

P: 35
From a quick look I'd say, try so that you initialize the array first

Expand|Select|Wrap|Line Numbers
  1. BitSet fingerprint2 = new BitSet[3]; 
  2. for(int i = 0; i < fingerprint2.length;i++ ) {
  3.    fingerprint2[i] = new BitSet();
  4. }
  5. ....
  6. .. 
because the line
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. BitSet fingerprint2 = new BitSet[3]; 
  2. for(int i=0;i<counter;i++)
  3. {
  4.     fingerprint2[i] = new BitSet();
  5.     for(int j=0;j<1024;j++)
  6.     {
  7.         boolean bit = binData.readBoolean();    
  8.         fingerprint2[i].set(j,bit);         
  9.     }
  10.     System.out.println(fingerprint2[i]);    //nothing was printed out
  11. }
Jan 19 '07 #3

10K+
P: 13,264
I tried your suggestion, but nothing was printed out. Here is how i put it:
Expand|Select|Wrap|Line Numbers
  1. BitSet fingerprint2 = new BitSet[3]; 
  2. for(int i=0;i<counter;i++)
  3. {
  4.     fingerprint2[i] = new BitSet();
  5.     for(int j=0;j<1024;j++)
  6.     {
  7.         boolean bit = binData.readBoolean();    
  8.         fingerprint2[i].set(j,bit);         
  9.     }
  10.     System.out.println(fingerprint2[i]);    //nothing was printed out
  11. }
Then you are definitely getting an EndOfFileException.

Change your catch statements from
Expand|Select|Wrap|Line Numbers
  1. catch(EOFException eof)
  2. {
  3.  
  4. }
  5. catch(NullPointerException npe)
  6. {
  7.     System.out.println("Null Pointer");
  8. }
  9. catch (FileNotFoundException fe)
  10. {
  11.     System.out.println("No such file.");
  12. }
  13. catch (IOException ie)
  14. {
  15.     System.out.println(ie.toString());
  16. }
to


Expand|Select|Wrap|Line Numbers
  1. catch(EOFException eof)
  2. {
  3.     System.out.println("End of File Exception");
  4. }
  5. catch(NullPointerException npe)
  6. {
  7.     System.out.println("Null Pointer");
  8. }
  9. catch (FileNotFoundException fe)
  10. {
  11.     System.out.println("No such file.");
  12. }
  13. catch (IOException ie)
  14. {
  15.     System.out.println(ie.toString());
  16. }
And see if this isn't true.
Jan 19 '07 #4

P: 35
Then you are definitely getting an EndOfFileException.

Change your catch statements from
Expand|Select|Wrap|Line Numbers
  1. catch(EOFException eof)
  2. {
  3.  
  4. }
  5. catch(NullPointerException npe)
  6. {
  7.     System.out.println("Null Pointer");
  8. }
  9. catch (FileNotFoundException fe)
  10. {
  11.     System.out.println("No such file.");
  12. }
  13. catch (IOException ie)
  14. {
  15.     System.out.println(ie.toString());
  16. }
to


Expand|Select|Wrap|Line Numbers
  1. catch(EOFException eof)
  2. {
  3.     System.out.println("End of File Exception");
  4. }
  5. catch(NullPointerException npe)
  6. {
  7.     System.out.println("Null Pointer");
  8. }
  9. catch (FileNotFoundException fe)
  10. {
  11.     System.out.println("No such file.");
  12. }
  13. catch (IOException ie)
  14. {
  15.     System.out.println(ie.toString());
  16. }
And see if this isn't true.
Thanks, it work out already. =)
Jan 19 '07 #5

10K+
P: 13,264
Thanks, it work out already. =)
What did you do then?
Jan 19 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.