BlackBerry WebWorks API BlogToString Gotcha
First post, and its a real techy one…
So your coding away, you need to write some data to disc, your writing a Blackberry widget app. So where you do you look Blackberry Developer Zone, and cool you find some example code. It look easy enough, just convert your data to a Blob, call save great. It is done for you with a Blackberry java extension call stringToBlob
So this works wonderful!
Then you want to use the data later on, you read it back into a blob. But you need the data in a more usable format that a blob, so you check those example docs and what do you see – blogToString. Again the example is simple, this should be plain sailing.
NO – it is not. What do you get? A HUGE run time error. The simulator closes and no error message. Wonderful!
But why?
After searching on Google – it seems no one else has had this problem. I read the API documentation really, really carefully!
The stringToBlob call encodes data by default using UTF-16BE which is fair enough. But the blobToString method encodes data by default using ISO-8859-1 !
WTF – why did an API designer decide to use one encoding default in one place and a different one in the reverse.
I am sure there is a reason, no idea what! So if you are searching for ‘stringToBlob wont work’, or ‘blobToString crashes my app’ I hope you find this article and fix your problem about 3 hours faster than me!
