Category Archives: Android

Android ListView and ArrayIndexOutOfBoundsException

While working on an app with a native Navigation Drawer, I noticed that on Android 4.0.4 my app crashes. I could not get this exception on any other version of Android.

    java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
    at android.widget.AbsListView$RecycleBin.addScrapView(
    at android.widget.AbsListView.trackMotionScroll(
    at android.widget.AbsListView$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(

After spending about an hour trying to figure this out, I realized that my Adapter for the List View returned a value of 2 from the getViewTypeCount() method, and getItemViewType() returned a value of 1, or 2, depending on the type of view. The getItemViewType() is suppose to start with a value of 0, so it should be returning a value of 0 or 1, instead.

For example:

public class ActionBarDrawerAdapter extends BaseAdapter {
    public int getViewTypeCount() {
        return 2;
    public int getItemViewType(int position) {
        ActionBarDrawerItem item = (ActionBarDrawerItem) getItem(position);
        if (item.isSubnavItem()) {
            return 1;
        } else {
            return 0;

Adding kSOAP 2 to your Android Gradle project

I am working on an app that needs to communicate with a server using SOAP messages. I decided to use the kSOAP2-Android library, since is seems to be the most robust way to handle SOAP calls in Android.

To add the library as a dependency to your project, download the kSOAP2-Android JAR file into the libs directory in the project. (At the time of writing this, version 3.0 were the most current version)

Open the Gradle build file ( and add the kSOAP dependency (your dependencies block should look something like this)

dependencies {
    compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')

Now all you need to do is to clean the project.  That can be done from the command line, or from the Android Studio IDE.  From the command line, in your project directory, run “./gradlew clean”, then rebuild and run your app.

Screen Shot 2013-01-17 at 10.46.49 AM

Installing and Configuring the Google TV Emulator

The Google TV developers released a GoogleTV add-on for the Android SDK that makes emulation possible on the Windows and Mac Operating Systems (Linux was already supported).

Assuming that you have the Android SDK already installed:

In order to use the emulator, you need to open the Android SDK Manager and make sure that you have the “Google TV Addon” [under Android 3.2 (API 13)] and the “Intel Atom x86 System Image” [under Android 2.3.3 (API 10)].


If you installed the “Intel Atom x86 System Image”, you need to install the “Intel Hardware Accelerated Execution Manager” which can be found in the <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/
For Windows, install the IntelHAXM.exe file.  
For Mac, install the IntelHAXM.dmg file.
You can read the installation instructions here

Create a new “Device Definition” in the “Android Virtual Device Manager” using the configuration below.  
For 1080p use a resolution of 1920×1080 and a density of xhdpi.
For 720p use a resolution of 1080×720 with a density of tvdpi.


Then create a “Android Virtual Device” using the “Device Definition” that you just configured.


Google TV Logo

What is Google TV

What is Google TV?
Google TV is an Android based platform that brings live TV, web and android apps all together in one device. It is like having a computer, cell phone, and television all in one.

Why develop for Google TV?
Did you know that the average person watches 5 hours of television every day? Due to this large amount of TV watching about 20% of televisions sold in 2010 were internet ready. Having this Google TV platform gives you the ability to develop apps that will enhance the TV viewing experience for millions of viewers. For example an app focused on sports can bring the most up to date statistics, video content and game scores to each viewer on personal demand.

Does developing for Google TV intrigue you? Well if it does then my next post will take you through the steps of how to get your Google TV development experience started.


Unlock and Root your Nexus One with Android 2.3.4

I recently received a Nexus One phone and did all of the updates almost immediately. What I did not realize was that the phone does not have root by default, so I started searching to see if I can root a Nexus One running Gingerbread (Android 2.3.4). I found a lot of older information, and some pretty tedious methods, involving downgrades.

I then found a way to unlock the Bootloader on the Nexus One, and got root!

This is what I did:
Unlocking the Bootloader 1

  1. Install the Android SDK.
  2. Power off the device, and then power it back on, while holding the trackball. This will get you into bootloader mode.
  3. Connect the phone to your computer.
  4. Download and Extract fastboot
  5. Go to your command prompt/terminal and run the fastboot file from where you extracted it to:
    • Windows: Type ‘fastboot-windows oem unlock’
    • Linux: Type ‘./fastboot-linux oem unlock’
    • Mac: ‘./fastboot-mac oem unlock’

    This should pop up a message on your device asking you to verify that you want to unlock the bootloader. With the volume +/- go to YES and press the power button.

Rooting the Phone and installing a Recovery Image 2

  1. Download and add to your SD Card.
  2. Download fastboot and unzip it.
  3. Download the recovery image and place it in the same directory where you unzipped fastboot.
  4. Power off the device, and then power it back on, while holding the trackball. This will get you into bootloader mode.
  5. Connect the phone to your computer.
  6. Go to your command prompt/terminal and run the following commands in the directory where you unzipped fastboot:
    1. fastboot devices
    2. fastboot flash recovery recovery-RA-passion-v2.2.1.img
  7. With the volume +/- buttons on the phone, move to “Bootloader” and press the power button.
  8. Again, with the volume +/- buttons, move to “Recovery” and press the power button.
  9. Use the trackball and move down to “Flash zip from SD Card”, and press the trackball to select.
  10. Select (you copied this in step 1) and press the trackball to select.
  11. When this is done, go ahead and reset the phone, you should now have root. You can verify this with the “Root Check” app, available from the market.