Skip to content
Advertisement

Pyjnius custom java method returning ‘JavaException: Unable to find a None Method’ works after Public Static

So I needed to read a ByteArray from the InputStream in Android. Therefore I used this custom method in java in a kivy App using pyjnius for the same reason as stated in the link.

I placed the ReadInput.java file in this directory:
~/Build_Environ/.buildozer/android/platform/build/dists/JniusPrintBluetoothAppie/src/main/java/org/kivy/android

I initialised the java class with pyjnius:

JavaScript

The java code:

JavaScript


I read from the buffer in python using the following code:

JavaScript

But for some reason this above code constantly gave me the following error:
JavaException: Unable to find a None Method

After many, many days of struggle I finally got the method to work by simply declaring the method as: public static The new java method looked as follows and I called it in the same way as above:

JavaScript



What I want to know is why would the word ‘static’ make the java method suddenly work?

Advertisement

Answer

The reason is that in Python code you access the method in a static way:

JavaScript

This will work only if you define the method inputread in Java as static.

But it was not necessary. It could better to keep the method as non-static in Java and to use it in Python in a normal non-static way:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement