runtime error NoSuchMethodError occurs for interface feature of director

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

runtime error NoSuchMethodError occurs for interface feature of director

cybergalaxy
Dear swig developer,
Thank you for your great work, with swig help, I am happy to find I can provide interface for all popular language.

I am using swig-3.0.10 to provide java/android interface for a c++ library, this interface include some listener/callback, which is my focusing, I try to provide interface API which is nature for java API users, and during that, I found something wrong, basically the code like:
PAProviderListener.hpp:
struct PAProviderListener
{
    virtual const std::string& getAppResourcePath() = 0;
    virtual void authRequested(PAProvider* pv, const char* username, const char* domain) = 0;
    ...
};

PAProvider.hpp:
struct PAProvider{
    virtual void addListener(PAProviderListener* listener) = 0;
    virtual void removeListener(PAProviderListener* listener) = 0;
    ...
}
Pineapple.i:
%module(directors="1") Pineapple
%include "stdint.i"
%include "std_string.i"
%include "typemaps.i"
%include <swiginterface.i>
%interface_impl(PAProviderListener);
%feature("director", assumeoverride=1) PAProviderListener;
%include "PAProviderListener.hpp"
%extend PAProvider{
        static PAProvider* create(PAProviderListener* listener) {
            return factory_create_and_start(context, listener);
        }
};
I can use swig to generate interface PAProviderListener and proxy PAProviderListenerSwigImpl and other java, jni code, and it pass the compilation, but it fails at runtime:
Process: com.siriustek.sipresence, PID: 10077
  java.lang.NoSuchMethodError: no static method with name='SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath' signature='(Lcom/siriustek/pineapple/PAProviderListener;)Ljava/lang/String;' in class Lcom/siriustek/pineapple/PineappleJNI;
   at com.siriustek.pineapple.PineappleJNI.swig_module_init(Native Method)
   at com.siriustek.pineapple.PineappleJNI.<clinit>(PineappleJNI.java:412)
   at com.siriustek.pineapple.PAProviderListenerSwigImpl.<init>(PAProviderListenerSwigImpl.java:78)
Looks swig generate java function:
  public static String SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath(PAProviderListenerSwigImpl jself) {
    return jself.getAppResourcePath();
  }
While generate jni method:
    {
      "SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath", "(Lcom/siriustek/pineapple/PAProviderListener;)Ljava/lang/String;"
    },
In generated java code, it use proxy class name PAProviderListenerSwigImpl, while at jni callback method, it use interface name PAProviderListener. I checked swiginterface.i, looks like typemap to javainterfacename which means name in interface feature define "%(rstrip:[SwigImpl])s", it should be PAProviderListener? why comes with proxy class name PAProviderListenerSwigImpl? I have no idea.

Please be noticed that below feature definition will cause error:
%interface_custom("PAProviderListenerSwigImpl", "PAProviderListenerInterface", PAProviderListener)
while it works:
%interface_custom("%sSwigImpl", "%(rstrip:[SwigAbstract])sInterface", PAProviderListener)
Is it a problem?

Thanks and best regard,
Xin Luo
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: runtime error NoSuchMethodError occurs for interface feature of director

William S Fulton
I can't replicate this. Can you provide a single interface file with
all the code and your java run file too?

William

On 2 September 2016 at 04:37,  <[hidden email]> wrote:

> Dear swig developer,
> Thank you for your great work, with swig help, I am happy to find I can provide interface for all popular language.
>
> I am using swig-3.0.10 to provide java/android interface for a c++ library, this interface include some listener/callback, which is my focusing, I try to provide interface API which is nature for java API users, and during that, I found something wrong, basically the code like:
> PAProviderListener.hpp:
> struct PAProviderListener
> {
>     virtual const std::string& getAppResourcePath() = 0;
>     virtual void authRequested(PAProvider* pv, const char* username, const char* domain) = 0;
>     ...
> };
>
> PAProvider.hpp:
> struct PAProvider{
>     virtual void addListener(PAProviderListener* listener) = 0;
>     virtual void removeListener(PAProviderListener* listener) = 0;
>     ...
> }
> Pineapple.i:
> %module(directors="1") Pineapple
> %include "stdint.i"
> %include "std_string.i"
> %include "typemaps.i"
> %include <swiginterface.i>
> %interface_impl(PAProviderListener);
> %feature("director", assumeoverride=1) PAProviderListener;
> %include "PAProviderListener.hpp"
> %extend PAProvider{
>         static PAProvider* create(PAProviderListener* listener) {
>             return factory_create_and_start(context, listener);
>         }
> };
> I can use swig to generate interface PAProviderListener and proxy PAProviderListenerSwigImpl and other java, jni code, and it pass the compilation, but it fails at runtime:
> Process: com.siriustek.sipresence, PID: 10077
>   java.lang.NoSuchMethodError: no static method with name='SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath' signature='(Lcom/siriustek/pineapple/PAProviderListener;)Ljava/lang/String;' in class Lcom/siriustek/pineapple/PineappleJNI;
>    at com.siriustek.pineapple.PineappleJNI.swig_module_init(Native Method)
>    at com.siriustek.pineapple.PineappleJNI.<clinit>(PineappleJNI.java:412)
>    at com.siriustek.pineapple.PAProviderListenerSwigImpl.<init>(PAProviderListenerSwigImpl.java:78)
> Looks swig generate java function:
>   public static String SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath(PAProviderListenerSwigImpl jself) {
>     return jself.getAppResourcePath();
>   }
> While generate jni method:
>     {
>       "SwigDirector_PAProviderListenerSwigImpl_getAppResourcePath", "(Lcom/siriustek/pineapple/PAProviderListener;)Ljava/lang/String;"
>     },
> In generated java code, it use proxy class name PAProviderListenerSwigImpl, while at jni callback method, it use interface name PAProviderListener. I checked swiginterface.i, looks like typemap to javainterfacename which means name in interface feature define "%(rstrip:[SwigImpl])s", it should be PAProviderListener? why comes with proxy class name PAProviderListenerSwigImpl? I have no idea.
>
> Please be noticed that below feature definition will cause error:
> %interface_custom("PAProviderListenerSwigImpl", "PAProviderListenerInterface", PAProviderListener)
> while it works:
> %interface_custom("%sSwigImpl", "%(rstrip:[SwigAbstract])sInterface", PAProviderListener)
> Is it a problem?
>
> Thanks and best regard,
> Xin Luo
> ------------------------------------------------------------------------------
> _______________________________________________
> Swig-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...