Pyjnius: Exception calling PythonActivity.getWindow().setSoftInputMode(...)

Created on 22 Mar 2019  路  5Comments  路  Source: kivy/pyjnius

I get a pyjnius error with a lot of class method accesses I expect to work:

Traceback (most recent call last):
  File "jnius/jnius_export_class_pxi", line 752, in jnius.jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 699, in jnius.jnius.JavaMethod.ensure_method
jnius.jnius.JavaException: Unable to find a None method!

Steps to reproduce:

  1. Make a new folder with this main.py:
from jnius import autoclass
python_activity = autoclass('org.kivy.android.PythonActivity')
window = python_activity.getWindow()
window.setSoftInputMode(16)  # SOFT_INPUT_ADJUST_RESIZE
  1. Package as .apk:
    p4a apk --arch=armeabi-v7a --name test --package com.example.test --version 1 --requirements=kivy,python2 --private . (or python 3, you may need to add api and/or ndk api arguments if these aren't set in your path)

  2. Run and wait until it instant-terminates, and then check logcat. You'll see this:

Traceback (most recent call last):
  File "jnius/jnius_export_class_pxi", line 752, in jnius.jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 699, in jnius.jnius.JavaMethod.ensure_method
jnius.jnius.JavaException: Unable to find a None method!

Most helpful comment

closing as not a bug in pyjnius, please comment or reopen if you think this is wrong.

All 5 comments

Ok, I did some good old print debugging and the exact crashing line is window = python_activity.getWindow(), or in bigger context:

https://github.com/wobblui/wobblui/blob/653d6db66f60b3bc4165e68440ddfbe8d1460904/src/wobblui/sdlinit.pyx#L60

However, I can't think of a case where the Activity (which PythonActivity/SDLActivity derive from) wouldn't have getWindow() as documented here: https://developer.android.com/reference/android/app/Activity#getWindow()

Is this a bug then?

FWIW, ran into the same error with https://github.com/kivy/python-for-android/pull/1772 . Anyone having a clue whether this is a pyjnius bug or a user error on my side?

The error here is calling the method on the Activity class, not instance, the instance is accessible through the mActivity attribute.

here is a working code example https://gist.github.com/47b7b18855b38de3730e081682c558ce

hopefully it achieve what you are trying to do :).

closing as not a bug in pyjnius, please comment or reopen if you think this is wrong.

@tshirtman :balloon: :tada: thanks :heart:

Was this page helpful?
0 / 5 - 0 ratings