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:
I have run out of ideas to test and doing some Google searches turned up nothing. Any ideas?
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)