Page 1 of 1

[RAPT] JavaException: JVM Exception occured while using jnius

Posted: Sun Nov 29, 2020 12:24 pm
by DragoonHP

Code: Select all

        from jnius import autoclass
        PythonSDLActivity = autoclass('org.renpy.android.PythonSDLActivity')

        def show_ad():
            PythonSDLActivity.seeAd()
And here is the seeAd method in PythonSDLActivity

Code: Select all

    
    public void seeAd() {
        launchAd();
    }
And launchAd is defined as

Code: Select all

    
    public void launchAd(){
        Toast.makeText(this, "From function", Toast.LENGTH_LONG).show();
        mRewardedVideoAd.show();
    }
where mRewardedVideoAd is an instance of Rewarded Video Ad. I don't know what I'm doing wrong and the Traceback error isn't much help as it just shows, JVM Exception occured when I click on the button which calls show_ad function.

EDIT: The test ad plays fine if I set it to play as soon as its loaded.

Re: [RAPT] JavaException: JVM Exception occured while using jnius

Posted: Sun Nov 29, 2020 7:44 pm
by PyTom
At the very least, the problem is that you're calling a non-static method on PythonSDLActivity without an instance of the activity. You probably want:

Code: Select all

        from jnius import autoclass
        PythonSDLActivity = autoclass('org.renpy.android.PythonSDLActivity')

        def show_ad():
            PythonSDLActivity.mActivity.seeAd()
That doesn't mean it will work - I have no idea what your ad framework is trying to do. But this should at least get the call in.

Re: [RAPT] JavaException: JVM Exception occured while using jnius

Posted: Mon Nov 30, 2020 1:49 am
by DragoonHP
Thanks for the tip PyTom. Unfortunately, still getting the same error. I'm using admob.

Re: [RAPT] JavaException: JVM Exception occured while using jnius

Posted: Mon Nov 30, 2020 10:33 am
by PyTom
I don't support admob, so you may be on your own here. That being said, if you want to post the actual traceback, I can see if there's something there. I'd also suggest looking at the logcat output to see if there are error messages on the Java side of things.

Re: [RAPT] JavaException: JVM Exception occured while using jnius

Posted: Mon Nov 30, 2020 9:54 pm
by DragoonHP

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00action_other.rpy", line 537, in __call__
  File "game/script.rpy", line 15, in show_ad
JavaException: JVM exception occured

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "_layout/screen_main_menu.rpymc", line 28, in script
  File "E:\Ren'Py\renpy\ast.py", line 914, in execute
  File "E:\Ren'Py\renpy\python.py", line 2028, in py_exec_bytecode
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
  File "E:\Ren'Py\renpy\ui.py", line 297, in interact
  File "E:\Ren'Py\renpy\display\core.py", line 2702, in interact
  File "E:\Ren'Py\renpy\display\core.py", line 3518, in interact_core
  File "E:\Ren'Py\renpy\display\layout.py", line 998, in event
  File "E:\Ren'Py\renpy\display\layout.py", line 998, in event
  File "E:\Ren'Py\renpy\display\layout.py", line 998, in event
  File "E:\Ren'Py\renpy\display\screen.py", line 714, in event
  File "E:\Ren'Py\renpy\display\layout.py", line 998, in event
  File "E:\Ren'Py\renpy\display\layout.py", line 998, in event
  File "E:\Ren'Py\renpy\display\behavior.py", line 962, in event
  File "E:\Ren'Py\renpy\display\behavior.py", line 897, in handle_click
  File "E:\Ren'Py\renpy\display\behavior.py", line 320, in run
  File "renpy/common/00action_other.rpy", line 537, in __call__
  File "game/script.rpy", line 15, in show_ad
  File "jnius/jnius_export_class.pxi", line 562, in jnius.jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 656, in jnius.jnius.JavaMethod.call_method
  File "jnius/jnius_utils.pxi", line 43, in jnius.jnius.check_exception
JavaException: JVM exception occured

I didn't see anything in logcat but will look again.

Re: [RAPT] JavaException: JVM Exception occured while using jnius

Posted: Tue Dec 01, 2020 11:40 am
by PyTom
If you're getting that, there should be a JVM exception logged. It's possible you will need to run logcat by hand, as the one used by Ren'Py filters out exceptions that don't come from Ren'Py, SDL, or Python. Since you're developing in Java, you'll have to use the Android tools to see errors.