• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Error Updating Record Flag

 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 531
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try raf.writeByte((byte)0xFF);
 
I was her plaything! And so was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic