Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Updating Record Flag

 
Daniel Simpson
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my delete method, I need to change the flag from 00 to 0xFF. I do this: However, when I do tests, I get strange results because of that value I know that when I read 0xFF from my datafile, it comes out as -1. Am I using the correct write method to write 0xFF. Does the negative sign count as a byte? Because that may be why my program is getting thrown off? I ran a simple test where I updated the flag in my first record by executing the code above. When I then ran my class to read all my records, I get weird results. However, when I went back and executed the line above, but instead wrote dbReader.writeByte(00), and ran my class again, it worked perfectly. So something is getting messed up when I write 0xFF. Any ideas on why it is doing this?

Here's a snippet of my code just so you can understand what's going on:
I just wanted to read 2 records and see what the results were. My first record's flag is -1 (0xFF) and the 2nd record's flag is 0. Here is what I get when I do my output:
-1
66
CRAP!

[ November 21, 2004: Message edited by: Daniel Simpson ]
 
Matt Sheehan.
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, when I do tests, I get strange results because of that value I know that when I read 0xFF from my datafile, it comes out as -1.

Since a byte is a signed number in Java, its interpreted as -1, so thats the correct result.

As for your code, it may be that you need to insert
into your flag == -1 clause.
[ November 21, 2004: Message edited by: Matt Sheehan. ]
 
Daniel Simpson
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out what happend thanks to you!!!

What happens is, is that if the flag is -1, all it will do will insert null values into my contractor object. HOWEVER, it doesn't skip the bytes, so the next time I tried to read the second record, it attempts to read the flag from my first datafield. Thank you!!!
[ November 21, 2004: Message edited by: Daniel Simpson ]
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try raf.writeByte((byte)0xFF);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic