473,388 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

HELP!!BitSet set() returns null..

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
5 1849
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
Thanks, it work out already. =)
What did you do then?
Jan 19 '07 #6

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

Similar topics

2
by: Rene van Hoek | last post by:
Hi, I am using Xalan 1.8.0 and Xerces 2.6.0 in C++. I have an XML document which I first transform into an other XML document using an XSL styelsheet. Then I want to parse with XPathEvaluator...
1
by: Suresh | last post by:
Hi, I have an C# CSEXE.exe (CSexe.cs) and a CSDll.dll (CSdll.cs). exe is compiled with a reference to dll. Calling for the class Type defined in CSDLL.dll using Type.GetType(...
4
by: audipen | last post by:
I have a problem with System.Type.GetType method. If you try out the following code in C# console app .. System.Type t = System.Type.GetType("System.DateTime"); System.Type t1 =...
2
by: Jeff Adams | last post by:
I am using MSVC .NET to create a C program. I am having trouble creating a window. The createwindow returns NULL however no error is caught. The GetLastError() returns "operation completed...
1
by: BeckyB00 | last post by:
Slightly different situation from the question of the 11/18/05 but the same error. (I'm just learning about web services so this is based on a 'quick tutorial') I'm running a web service using...
11
by: MLH | last post by:
I have 2 lines in a procedure that assign MyVariant a value - line #238 and line #491. When line #238 runs, the value is 152. When line #491 runs, the DLookup function returns Null. I would expect...
1
by: js | last post by:
I am using the following C# code and T-SQL to get result object from a SQL Server database. When my application runs, the ExecuteScalar returns "10/24/2006 2:00:00 PM" if inserting a duplicated...
6
by: Peter Michaux | last post by:
Suppose I have implemented a language with garbage collection in C. I have wrapped malloc in my own C function. If malloc returns NULL then I can run the garbage collector and then try malloc...
2
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.