Android : java.lang.NoSuchField Exception for mSurface while trying use surface from native

StackOverflow https://stackoverflow.com/questions/14976823

Question

I want to feed buffer of the surface from Native code. So I get the surface from SurfaceView's SurfaceHolder's getSurface method. Now all I want is to use it from the native to feed buffer to render image. I have included SurfaceClinger/Surface.h. But when I try to get mSurface property, it throws error saying java.lang.NoSuchFieldException for mSurface. Any suggestion in this regard will be helpful.

code snippet:

Surface       mSurface;
SurfaceHolder mSurfaceHolder;

mSurface = mSurfaceHolder.getSurface();

try{
    class myClass = mSurface.getClass();
    String fieldName = "mSurface";
    Field field = myClass.getDeclaredField(fieldName);
    field.setAccesssible(true);
    int surfacePtr = field.getInt(mSurface);
    nativeInterface.DrawOnSurface(surfacePtr);
}
catch(Exception ex){}

Thanks.

Était-ce utile?

La solution

From gingerbread onwards, the field name is different. By replacing fieldname from 'mSurface' to 'mNativeSurface' the problem is solved. for froyo and below 'mSurface' will work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top