[RAPT] JavaException: JVM Exception occured while using jnius

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

[RAPT] JavaException: JVM Exception occured while using jnius

#1 Post 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.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#2 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

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

#3 Post by DragoonHP »

Thanks for the tip PyTom. Unfortunately, still getting the same error. I'm using admob.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#4 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

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

#5 Post 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.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

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

#6 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Lacha, Semrush [Bot]