problem calling a Java Method from C++

hi everyone,

i'm using JNI and i'm trying to call a Java method from C++, this is the code:

SocketC.java

public class SocketC

{

private native void conectaServidor();

private void recibeBuffer()

{

System.out.println("HELLO!!!");

}

public static void main(String args[])

{

SocketC SC = new SocketC();

SC.conectaServidor();

}

static {

System.loadLibrary("Server_TCP");

}

}

Server_TCP.cpp

char* recibirSock()

{

int _flag = 1;

while(_flag != 0)

{

memset(buffer,0,sizeof(buffer));//Et la, celle pour recevoir

recv(sock,buffer,sizeof(buffer),0);

printf(" Mensaje del cliente: %s\n",buffer);

_flag = strcmp(buffer,"salir");

}//fin while

return buffer;

}

void enviarSock()

{

int _flag = 1;

getchar();

while(_flag != 0)

{

memset(buffer,0,sizeof(buffer));//procedimiento para enviar

printf("\n Escriba: ");

gets(buffer);

//err=scanf("%s",buffer);

send(sock,buffer,sizeof(buffer),0);

_flag = strcmp(buffer,"salir");

}//fin while

}//fin enviarSock

DWORD servicio(LPVOID lpvoid)//

{

char *buf;

printf("\nCliente aceptado!!!!!\n");

buf=recibirSock();

return 0;

}

JNIEXPORT void JNICALL Java_SocketC_conectaServidor(JNIEnv *env, jobject obj)

//void main()

{

/*this is the problem i'm calling the method recibeBuffer*/

jclass cls = env->GetObjectClass(obj);

jmethodID mmid = env->GetMethodID(cls, "recibeBuffer", "(V)V");

if (mmid == 0)

return;

env->CallVoidMethod(obj, mmid); //llama a Java

WSAStartup(MAKEWORD(2,0),&wsa);//MAKEWORD dit qu'on utilise la version 2 de winsock

printf("TCP conexion Sockets\n\n");

//estimez vous heureux que je foute pas de copyright ;)

system("TITLE TCP Conexion Sockets (Version server)");

//fo avouer que c'est plus joli

int port;

printf("Port : ");//On demande juste le port, pas besoin d'ip on est sur un server

scanf("%i",&port);

sinserv.sin_family=AF_INET;//Je ne connais pas d'autres familles

sinserv.sin_addr.s_addr=INADDR_ANY;//Pas besoin d'ip pour le server

sinserv.sin_port=htons(port);

server=socket(AF_INET,SOCK_STREAM,0);//On construit le server

//SOCK_STREAM pour le TCP

bind(server,(SOCKADDR*)&sinserv,sizeof(sinserv));

//On lie les parametres du socket avec le socket lui meme

listen(server,SOMAXCONN);//On se met ?閏outer avec server, 0 pour n'accepter qu'une seule connection

printf(" Servidor conectado.");

while(1)

{

sinsize=sizeof(sin);

if((sock=accept(server,(SOCKADDR*)&sin,&sinsize))!=INVALID_SOCKET)

{//accept : acepta cualquier conexion

if (hReadThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)

servicio, 0, 0, &dwThreadID))

{

printf("\nHOLA!");

GetExitCodeThread(hReadThread,&dwExitCode);

CloseHandle (hReadThread);

}

else

{

// Could not create the read thread.

printf("No se pudo crear");

exit(0);

}

}

}

}

when i'm running the proyect i get this error:

C:\POT Files\UCAB\tesis\esmart\french>java SocketC

Exception in thread "main" java.lang.NoSuchMethodError: recibeBuffer

at SocketC.conectaServidor(Native Method)

at SocketC.main(SocketC.java:16)

i don't know why this is happening i got declare the method recibeBuffer in my SocketC.java class, but doesn;t work can anyone help me?

PD: sorry for my bad english i'm from Venezuela

[3789 byte] By [Bianconero_ccsa] at [2007-10-3 1:31:24]
# 1

Next time please paste your code between [code] tags with the code button just above the edit message area.

To answer your question, you wrote the wrong method signature. It should be:jmethodID mmid = env->GetMethodID(cls, "recibeBuffer", "()V");

Regards

jfbrierea at 2007-7-14 18:29:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
thanx for the reply, i've solve my problem
Bianconero_ccsa at 2007-7-14 18:29:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...