Android, Eclipse and Java – First Experiences

After bitching about the lack of good tutorials last time, I found that I’d actually been looking at Android 1.1 tutorials and trying to run them on Android 1.5.

Now that 1.5 is out (well, it was released quite a while ago, but I’ve only recently started using it in earnest) I’ve re-read the tutorials and some of the introductory info on the Android Developer’s Guide. In my exploring I’ve hit MANY “Force Close” dialogs.  Unfortunately they never seem to say anything about WHY the app is being forced to close.ForceClose

The first few times I’ve just popped Eclipse into debug mode in an attempt to figure out what’s wrong.  Unfortunately it doesn’t seem to help much.The exceptions that end up being thrown seem really vague and not entirely related to the issue at hand.  So without any further blabbing, here are my top three reasons for getting a “Force Close” in my Android development:

1. Putting the call to setContentView at the end of the onCreate method instead of the start.

Initially I thought I’d be clever and first setup all my event handlers, and data binding and stuff.  But after some really confusing exceptions I realised that unless I call setContentView at the top of my onCreate, I won’t have access to any of the “objects” on my form.

2. Having an abstact class instead of a concrete class for my Activity

I’m not entirely sure how Eclipse and I came to this point, but somehow when adding this class I must have ticked a box that I hadn’t ticked before and suddenly the class was abstract.  No idea how or why this happened, and I certainly didn’t notice it at the time.

Of course I’d expect the exception to say something about “You cannot create an instance of an abstract class.” or something  meaningful like that.  But no, it seemed that this was not to be.

3. Not adding the Activity to the AndroidManifest.xml

This happened at the same time as the issue in point two so I’m not too sure if the two issues together just made the cause of the problem really hard to find.   Maybe I’m just too used to Visual Studio protecting me from myself, but this seemed a little silly.  I created a class that extends Activity.  Now I still need to go and add that info to the AndroidManifest.xml file?  I

People might think that I’ve been overly coddled by VS.Net, and that this is simply how normal development works.  If I used a Wizard to credit an Invoice, I’d expect to have a credit note created at the end, ready to send on to the client.  I wouldn’t expect to have to then go and specify the Client, and add the information for the line items, and then add up the totals manually and then finally to add on the VAT before I could send it.

There are a few nice wizards to get things started, but they often seem to only go half way. If I use a wizard, I expect the wizard to do the whole job.  So when I add an Activity to an Android app, I’d expect it to create the class AND enter the information into the AndroidManifest.xml file for me. Actually, in this case there is really no Wizard in the SDK toolkit to add the Activity – and that’s another gripe – there are wizards to create an Android XML file which is relatively easy to do.  But something like creating a new Activity requires a bunch of manual steps.  So where’s the consistency?

Anyway – enough whining.  Soon I’ll face the anger of a mob of Java developers. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *