I try to avoid blogging about tech-related stuff on here, because I don't enjoy boring people to tears. However, after spending several days banging my head against a stupid problem, I wanted to post my solution here in the hopes that future generations of Google-searchers may get some relief.
So, here was my deal.
Stop me if you've heard this one:
"My program runs just fine on my PC, but it doesn't work on the phone!"
You've just summarized the entire state of mobile development. Once you really UNDERSTAND that statement, you're well on your way to becoming a good mobile developer.
In this particular case, I was deploying a J2ME program for the first time in over two years. On the whole, I was pleasantly surprised at how quickly stuff has been coming back to me - the whole multi-threaded model, the byzantine world of JSRs, the way the keys and the screen work. There are still definitely some rusty spots, though... I tore out my initial approach at data persistence because I wasn't grokking RecordStores properly. That paled in comparison to just getting the darn thing to run, though.
Oh, don't get me wrong, it runs perfectly fine within EclipseME. And within the OEM emulators that I've downloaded. But since I'm just one guy and not a development shop, I have exactly one actual device to test on: my personal Sprint J2ME phone, a Sanyo 7400. And any time I tried to download the JAD, up would pop a wonderful error: "Data Error 906. Invalid Descriptor Attribute Format."
I HATE this error. I did as all good engineers did and googled thoroughly, only to find out that this error just means "something, somewhere, somehow, is wrong with your JAD or MANIFEST.MF file". There were all sorts of helpful tips: Make sure all your lines end with a linefeed and no carriage return! Make sure you aren't missing any required attributes! Make sure the JAD and manifest files match exactly! Except for the attributes that aren't required in both! Except for the particular phones that do want them there! Most aggravating for me, there doesn't seem to be any way to find out WHICH attribute it doesn't like.
I tried all sorts of things. Every fix would continue to work fine on my local machine, but my Sanyo stubbornly refused to play ball. I thought I was onto something earlier tonight, when I realized that the manifest file was enforcing the 72 character limit and pushing extra characters onto the following line. I pulled my MIDlet class all the way back out from "us.cirion.(something).ui.mobile" to just "us.cirion", and trimmed out my install-notify and delete-notify lines, and once I saw that everything was back under 72 characters, I was sure it would be a success.
Nope.
After all that, I finally - finally! - figured out the problem. It's actually the very first entry in EclipseME's JAD editor: "Midlet Jar URL". See, I had put the name of my Jar in there, which seems perfectly valid - after all, the jad and the jar are in the same directory, so it should be able to find the jar, right? Only, it turns out, it can't. At least on the Sanyo 7400, the MIDlet-Jar-URL really IS a URL. So, instead of "MyApp.jar", it had to be "http://mydomain.com/location/MyApp.jar".
As usual in this line of work, the amount of time spent finding a problem is inversely proportional to the difficulty in fixing it. As soon as I realized what the issue was, it was a super-quick change. I popped it onto the phone, and went on my merry way.
And AFTER I found the problem, I saw that Sun had an article from way back in 2002 describing the steps to properly deploy a JAR. I'm sure that all of this is extremely obvious to real J2ME developers, hence the fact that none of my Google searches flagged that field as a potential problem. Now that I've run into it myself, I can be certain I won't make this mistake again. I'll probably be looking into Antenna as a way to hopefully help automate the translation from local URL to remove.
No comments:
Post a Comment