JNI,单个文件中的多个java类

时间:2014-05-11 11:11:20

标签: java c++ android-ndk java-native-interface sdl

我在Android上的SDL2中遇到了一些问题,我无法获得我的窗口的分辨率(我尝试的所有内容都返回0x0或崩溃)。所以我试图通过将解决方案直接从java发送到c ++来解决这个问题,不幸的是,每当我尝试调用我的本机方法时,我的应用程序崩溃了。

The SDLActivity.java file contains multiple classes.



 public class SDLActivity extends Activity {
 //some code
}
class SDLMain{
//more code
}

class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, 
    View.OnKeyListener, View.OnTouchListener, SensorEventListener  {
protected static float mWidth, mHeight;

public void surfaceChanged(SurfaceHolder holder,
                               int format, int width, int height) {
//Code, including code that sets mWidth and mHeight
}
}

还有很多其他的类。

现在,在SDLSurface类中,我一直在尝试创建一个将mWidth和mHeight发送到我的c ++代码的本机方法,不幸的是,每当我调用此方法时,我的应用程序崩溃。

native void passResolution(float w, float h);

在我的main.cpp

JNIEXPORT void JNICALL Java_org_libsdl_app_SDL_SDLActivity_passResolution(JNIEnv* env, jobject thiz, jfloat w, jfloat h)
{
    windowWidth = w;
    windowHeight = h;
}

我似乎无法弄清楚我做错了什么。有没有人有任何想法?

异常:[2014-05-11 14:27:17 - ddms] Can't bind to local 8653 for debugger [2014-05-11 14:27:18 - ddmlib] De software op uw hostcomputer heeft een verbinding verbroken java.io.IOException: De software op uw hostcomputer heeft een verbinding verbroken at sun.nio.ch.SocketDispatcher.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(Unknown Source) at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.write(Unknown Source) at sun.nio.ch.SocketChannelImpl.write(Unknown Source) at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213) at com.android.ddmlib.Client.sendAndConsume(Client.java:642) at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:348) at com.android.ddmlib.Client.requestAllocationStatus(Client.java:488) at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:835) at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:803) at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:621) at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:44) at com.android.ddmlib.DeviceMonitor$3.run(DeviceMonitor.java:580)

0 个答案:

没有答案