Error calling method on NPObject! in Android 2.2

后端 未结 6 642
轻奢々
轻奢々 2021-01-11 16:45

I\'m using addJavascriptInterface within my Android application to allow JavaScript to invoke functions I\'ve created in my native Java application.

This worked well

6条回答
  •  盖世英雄少女心
    2021-01-11 17:19

    In my experience this problem is caused by Javascript interfaces bringing back objects that Javascript doesn't automatically identify.

    In Android this is caused by wrappers like Boolean or Long in comparison to their native versions boolean and long.

    //This will fail
    public Long getmyLongVal() {
        return 123456789;
    }
    
    //This will work
    public long getMyNativeLongVal() {
        return 123456789;
    }
    

    So remove your wrapper classes to any methods being used by Javascript if you want to avoid NPObject errors.

提交回复
热议问题