luajava.bindClass raise classNotFindException #65

Closed
opened 2020-01-16 09:43:34 +00:00 by Justice-love · 4 comments
Justice-love commented 2020-01-16 09:43:34 +00:00 (Migrated from github.com)
  • platform: android
  • usage: luajava.bindClass and then raise classNotFindException
Caused by: org.luaj.vm2.LuaError: @Pic.lua:14 vm error: java.lang.ClassNotFoundException: com.ai.ipu.push.test.mock.edgehandle.recgnition.ObjRecApi
        at org.luaj.vm2.lib.jse.LuajavaLib.invoke(Unknown Source)
        at org.luaj.vm2.lib.VarArgFunction.call(Unknown Source)
        at org.luaj.vm2.LuaClosure.execute(Unknown Source)
        at org.luaj.vm2.LuaClosure.call(Unknown Source)
        at com.zzx.script.LuaScriptEngine.execute(LuaScriptEngine.java:38)
  • what i think
    luaj use java.lang.ClassLoader#getSystemClassLoader to load app class in org.luaj.vm2.lib.jse.LuajavaLib#classForName

  • lua script

local cksName = 'com.ai.ipu.push.test.mock.edgehandle.recgnition.ObjRecApi'

function preNanoEnv(params)
    local objRecApi = luajava.bindClass(cksName)
    local rootPath = params[0]
    return objRecApi:preNanoEnv(rootPath)
end
* platform: android * usage: luajava.bindClass and then raise classNotFindException ``` Caused by: org.luaj.vm2.LuaError: @Pic.lua:14 vm error: java.lang.ClassNotFoundException: com.ai.ipu.push.test.mock.edgehandle.recgnition.ObjRecApi at org.luaj.vm2.lib.jse.LuajavaLib.invoke(Unknown Source) at org.luaj.vm2.lib.VarArgFunction.call(Unknown Source) at org.luaj.vm2.LuaClosure.execute(Unknown Source) at org.luaj.vm2.LuaClosure.call(Unknown Source) at com.zzx.script.LuaScriptEngine.execute(LuaScriptEngine.java:38) ``` * what i think luaj use `java.lang.ClassLoader#getSystemClassLoader` to load app class in `org.luaj.vm2.lib.jse.LuajavaLib#classForName` * lua script ``` lua local cksName = 'com.ai.ipu.push.test.mock.edgehandle.recgnition.ObjRecApi' function preNanoEnv(params) local objRecApi = luajava.bindClass(cksName) local rootPath = params[0] return objRecApi:preNanoEnv(rootPath) end ```
BigZhou15717498850 commented 2020-01-16 09:45:42 +00:00 (Migrated from github.com)

I also encountered this problem

I also encountered this problem
Mikhael-Danilov commented 2020-03-23 23:18:15 +00:00 (Migrated from github.com)

I believe luaj itself would do nothing with this issue (as it android platform specific issue), your code however can:

I believe luaj itself would do nothing with this issue (as it android platform specific issue), your code however can: - Create your own class loader as in: https://github.com/NYRDS/remixed-dungeon/blob/d884050a6ada32daeb42283b4f06f20fa09a9dcd/RemixedDungeon/src/main/java/com/nyrds/android/lua/MultiDexLuajavaLib.java#L13 - Load it in your lua state as in: https://github.com/NYRDS/remixed-dungeon/blob/d556e6c0d5f07765f59e1da39e5af6facf6d9c9d/RemixedDungeon/src/main/java/com/nyrds/android/lua/LuaEngine.java#L114
IoIxD commented 2023-01-05 04:56:13 +00:00 (Migrated from github.com)

Better late then never: This was valid at some point. But as of 2.0.1 (before you think of downgrading, that version is ten years old and isn't even close to the one this repo) you can only bind Java classes.

I suggest this change be reverted. I cannot think of a good reason for this.

Better late then never: This was valid at some point. But as of 2.0.1 (before you think of downgrading, that version is ten years old and isn't even close to the one this repo) you can only bind Java classes. I suggest this change be reverted. I cannot think of a good reason for this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#65