6

Getting NullPointerException when trying to start avd. I just downloaded the ADT bundle for Mac and ran android avd. Anyone know why it would fail?

$ ./android avd
java.lang.NullPointerException
    at com.android.sdklib.internal.avd.AvdInfo.getDeviceName(AvdInfo.java:158)
    at com.android.sdkuilib.internal.repository.ui.DeviceManagerPage.fillDevices(DeviceManagerPage.java:497)
    at com.android.sdkuilib.internal.repository.ui.DeviceManagerPage.fillTable(DeviceManagerPage.java:357)
    at com.android.sdkuilib.internal.repository.ui.DeviceManagerPage.createContents(DeviceManagerPage.java:259)
    at com.android.sdkuilib.internal.repository.ui.DeviceManagerPage.<init>(DeviceManagerPage.java:130)
    at com.android.sdkuilib.internal.repository.ui.AvdManagerWindowImpl1.createDeviceTab(AvdManagerWindowImpl1.java:210)
    at com.android.sdkuilib.internal.repository.ui.AvdManagerWindowImpl1.createContents(AvdManagerWindowImpl1.java:193)
    at com.android.sdkuilib.internal.repository.ui.AvdManagerWindowImpl1.open(AvdManagerWindowImpl1.java:133)
    at com.android.sdkuilib.repository.AvdManagerWindow.open(AvdManagerWindow.java:94)
    at com.android.sdkmanager.Main.showAvdManagerWindow(Main.java:369)
    at com.android.sdkmanager.Main.doAction(Main.java:311)
    at com.android.sdkmanager.Main.run(Main.java:119)
    at com.android.sdkmanager.Main.main(Main.java:102)
Vineet Bhatia
  • 2,469
  • 4
  • 30
  • 28

6 Answers6

13

The following worked for me:

From the command line I navigated to the tools folder of the Android-SDK folder. From there I ran this command:

android list avd

This produced a list of all of my virtual devices but one of them showed itself to be the problem. The exact output was as follows:

The following Android Virtual Devices could not be loaded:
   Name: Tab31
   Path: /Users/User/.android/avd/Tab31.avd
   Error: Failed to parse properties from /Users/User/.android/avd/Tab31.avd/config.iniere

If you see this then make note of the "Name" property ("Tab31" in my situation) and run the following command (obviously replacing the name of my AVD with yours):

android delete avd -n Tab31

After that I was able to start the AVD Manager without any problem.

BreakingBrad
  • 256
  • 2
  • 8
  • Tried 'android list avd', I receive a 'Exception in thread "main" java.lang.NullPointerException' at at java.io.File.(File.java:277) at com.android.sdklib.internal.avd.AvdManager.parseAvdInfo(AvdManager.java:1616)..... – MSIslam Mar 14 '16 at 15:41
  • This might help: http://stackoverflow.com/questions/30345134/nullpointerexcepton-in-android-studio-plugin-android-support – BreakingBrad Mar 14 '16 at 19:49
4

I had this exact same problem last night and finally found the ways to get the emulator to start working:

List the available targets with: android list targets

android create avd -n {name} -t {targetID} (for {name} I chose Tablet - believe its arbitrary)

== Still wasn't working but then I discovered =>

I right-clicked above the manifest.xml file, selected option Run As -> Run Configurations -> on a tab Target, and selected AVD created.

(from Eclipse launch error when trying to run an Android app)

Community
  • 1
  • 1
vrwired
  • 116
  • 1
  • 5
3

If nothing of the above solutions work, deleting the .android folder in the home directory will work

MSIslam
  • 4,587
  • 6
  • 25
  • 28
  • Had an issue when "Loading devices" was stuck when upgraded from AS 4.0.2 to 4.1. Removed `.android` directory - issue got fixed, thanks. – azizbekian Oct 15 '20 at 18:55
2

I had this same problem after moving around my Android SDK and changing the base directory by setting the environment variable ANDROID_SDK_HOME. Turns out there is a path inside of the following file (path below ANDROID_SDK_HOME).

.android/avd/nameofphone.ini

The "path=" setting in that file is absolute, so if you move around your files it will not be correct anymore. Changing that to the correct absolute path to the avd-file in the same directory fixed my issue.

mikeplate
  • 1,149
  • 8
  • 10
  • I had the exactly problem, was going to reinstall Windows 7, you saved my day. In my case, the avd path in under my User folder, I had some legacy AVD ini files which target to android version that have not been installed. – coocood Dec 04 '12 at 02:48
  • In some reason I had no nameofphone.avd for one of avds, just .ini file. I just removed this .ini. – kaspartus Feb 03 '13 at 05:54
2

It's usually because creation of a new AVD failed or the configs for one of your AVDs is corrupted.

Go to ~/.android/avd

Check the list of AVDs. If you think one of those AVDs is causing the problems, sudo rm -r (UNIQUE PART OF AVD NAME)*

This removes that AVD. Then re-try android avd

@BreakingBad's solution works fine except when the config is corrupted

Akshar
  • 927
  • 9
  • 7
1

It looks like this issue has been fixed in version 21.0.1 preview 1 of the SDK Tools.

http://code.google.com/p/android/issues/detail?id=40400

The most likely cause is an invalid properties file that could not be parsed by the AVD Manager. Updating to the Preview Channel of the SDK Tools should fix this, or you can just wait for the official release.

Once I updated, the AVD Manager started and showed an invalid AVD in my list, which I was able to delete.

Matthew Blackford
  • 3,041
  • 1
  • 24
  • 28