|
-
Jan 19th, 2007, 12:00 AM
#1
Thread Starter
Junior Member
[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.
-
Jan 19th, 2007, 02:23 AM
#2
Thread Starter
Junior Member
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]);
}
-
Jan 19th, 2007, 05:04 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|