Question

Problem: MonkeyDevice getViewIdList() throws NullPointerException

How I got the error:

# Retyped, not copied, excuse typos.
$ monkeyrunner
>>> from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner
>>> device = MonkeyRunner.waitForConnection()
>>> device.getViewIdList()

Throws a java.lang.NullPointerException with the following traceback:

at com.android.chimpchat.ChimpManager.parseResponseforExtra(ChimpManager.java:216)
at com.android.chimpchat.ChimpManager.listViewIds(ChimpManager.java:392)
at com.android.chimpchat.adb.AdbChimpDevice.getViewIdList(AdbChimpDevice.java:604)
at com.android.monkeyrunner.MonkeyDevice.getViewIdList(MonkeyDevice.java:383)
... # Reflection stuff ...

Things I did to resolve:

  • Updated SDK to latest version (SDK Tools at 22.0.5, SDK Platform Tools at 18.0.1)
  • Same exception on 4.2.2 and 4.3 emulators

I have run out of ideas to test and doing some Google searches turned up nothing. Any ideas?

Was it helpful?

Solution

This actually happens because

device = MonkeyRunner.waitForConnection()

returns with no error or exception even when the connection was not successful.

You can use the same technique used by AndroidViewClient/culebra to detect if the connection has been done just after waitForConnection():

 try:
     device.wake()
 except java.lang.NullPointerException, e:
     print >> sys.stderr, "%s: ERROR: Couldn't connect to %s: %s" % (progname, serialno, e)
     sys.exit(3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top