Android App Development Diary: Entry Number 1

Travis Black's picture

Getting started with Android dev was a bit of a pain. Honestly, more than I thought it would be. I thought, its an open source platform, with millions of users and developers, and its created by Google. Surely there will be tons of examples on the web and getting started will be a breeze. Boy was I wrong.

The first thing I did when I decided to create an Android app was go to Google and search for Android SDK. The first result was the result I wanted and there was a nice link to a Zip file for Mac. Beneath were a great little set of instructions on how to get started. I moved the SDK files over to my ~/cl folder, which is where I keep all of my command line tools. I then opened up the "Detailed Instructions" for installing the SDK and thus began my journey. http://developer.android.com/sdk/installing.html

It was a little rough in the beginning, with downloading Eclipse, installing ADT, trying to decide which tools, platforms and Add On's to install, creating my VM, etc. I finished all of this up, and moved on over to "Hello World, Android Edition". Hello World was when I hit my first issue. In Hello World (http://developer.android.com/resources/tutorials/hello-world.html) about halfway down, you will notice where it is asking you to create your strings.xml file. Unfortunately, every time I edited this file (which was auto-generated), I got an annoying pop-up in eclipse stating: java.lang.NullPointerException and every time I clicked or attempted to edit this file, I got this error. I was going crazy, when finally, I deleted the file, created it from scratch, and it worked great. Finally, I was over my first hurdle and on my way towards real mobile app development.

With the first test out of the way, Hello World in the bag, I moved on to bigger and better fish. I tested out some of the "Hello Views" tutorials, but then decided to skip over that and just explore a sample app. The sample app I chose was the Contact Manager. I opened the sample app in Eclipse, and much to my chagrin, it wouldn't run. A similar error the the one in the "Hello World" debacle was the culprit. This time, I just copied all of the code for this app over from the location in my ~/cl folder and placed it in my default Eclipse workspace location. This, somehow, was all I needed to get this app compiling. I started to create my own app using code I copied from this one. After I got all of my views set up, and working just like the sample, it was time to start actually programming. No more copy paste for this ninja.

It has been 5 or 6 years since I have touched Java, but really, not much has changed. The only thing holding me down here was ramping up on a whole new framework/api and remembering how to read Java Docs. I put my Google Fu to good use and searched the thing that seemed the most important to me "Post to Web Service Android". This returned all kinds of responses. I went with what looked easiest first. It was something called RequestQueue. I saw it in a lot of examples so I gave it a shot. To anyone reading this, believe me, this is not your friend. android.net.http.RequestQueue I think this was deprecated back in 1.1 or some nonsense, so I spent a good while trying to get code that wasn't at all valid to work. After I realized this mistake, I made an effort to use the android http client code instead. android.net.http.AndroidHttpClientI spent a good long while messing around with this, not quite sure how it worked, and unable to find a good example online. I had code, that I thought should be working, but it just kept failing, so I gave up on that as well and moved on to the apache http client. org.apache.http.impl.client.DefaultHttpClient This was the way to go here. I found lots of tutorials online, and actually got my code running with this one (http://www.anddev.org/http_post_connection_in_sdk-10-t2970.html) but.... not for a while. I had the same code as these people had, yet it still wasn't working. At this point, I was becoming discouraged to no end. Thats when it all came together.

The first thing I did was find out how to do logging in Eclipse+android. I placed lines of code like this one:

Log.v(TAG, "Activity State: onCreate()");all through my code, then with a quick google search, I found that all I had to do to view the log was go to Eclipse->Window->Show View->Other->Android->Log Cat. This showed me a full log of everything as it happened in my application. I noticed a strange error though. UnknownHostException? What the heck was this. I googled it too of course, and after a few hits, found out that in the manifest.xml file, I needed to add a line like this:

<uses-permission android:name="android.permission.INTERNET" />

Finally, I ran my app one more time, I submitted the request, I tailed the apache logs on my web server, and I was pleased to see the request come through:
173.8.18.209 - - [29/Jun/2010:15:26:17 +0000] "POST /trail/create? HTTP/1.1" 200 1429 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

Finally, I have arrived. I can create and edit views in Android, I can make web requests, I can handle local events, and everything is right in the Universe. Lets see how the next few days goes. Listen in for an update!

Comments

HO1D3R's picture

Hi Travis, I am planning to start out on some Android development and am blogging about it too. I am just at that stage of working through some of the basic tutorials. I hope I don't have as many frustrations as you have had as I too haven't developed in Java for a few years.

Anonymous's picture

hi

i am a noob and was wondering what this means

173.8.18.209 - - [29/Jun/2010:15:26:17 +0000] "POST /trail/create? HTTP/1.1" 200 1429 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

does it mean the servlet is not available but the request came through?

zlzlzl's picture

Hi
I have the same problem ("Apache-HttpClient/UNAVAILABLE (java 1.4)").
Did you manage to fix it? if yes how?

thanks

zl