how to call java method with (int,int,String) parameters from c?

4,449 views
Skip to first unread message

MangeshHYD

unread,
Apr 27, 2012, 8:09:10 AM4/27/12
to andro...@googlegroups.com
Hi,
I want to call a java method from c.
e.g postFB(int id,int achId, String desc) is the java method.
 
what I am doing is

jmethodID postOnFB_mthd;

postOnFB_mthd=(*env)->GetMethodID(env,fwkClass,

"postFB","(IILjava/lang/String;)V");

I tried with above  but its crashing. What I have observed is when we want to pass 2 int parameters ,singnature will be something like

postOnFB_mthd=(*env)->GetMethodID(env,fwkClass,"postFB","(II)V"); but dont know how it should be when there is int and String parameter.

 

any help is appreciated.

Thanks,

Mangesh Kadam

 

 

Glenn Kasten

unread,
Apr 28, 2012, 1:02:41 PM4/28/12
to andro...@googlegroups.com
JNI is not my area of expertise, but I think that StackOverflow
is a good resource for non-Android-specific questions such as this.
Also try reading the NDK sample code or a JNI tutorial.

F.Stain

unread,
Apr 29, 2012, 6:49:24 AM4/29/12
to andro...@googlegroups.com
Hi  mangesh,

Look here :

jmethodID m_test_mthod_id = m_jniEnv->GetMethodID( m_class, "test_method", "(Ljava/lang/String;)V" );

void call_test_method( string param )
{
if( setupEnvironment() )
{
jstring jStringParam = m_jniEnv->NewStringUTF( param.c_str() );
if( !jStringParam )
{
LOG_ERR( "failed to alloc param string in java." );
return;
};
m_jniEnv->CallVoidMethod( m_object, m_test_mthod_id, jStringParam );
m_jniEnv->DeleteLocalRef( jStringParam );
teardownEnvironment();
};
};

Ok, you need to send (int, int, String), you only need to send two your int's before third jobject link.

MangeshHYD

unread,
May 9, 2012, 2:57:20 AM5/9/12
to andro...@googlegroups.com

Hi Frank,
thanks for the reply. Its working now.
regards,
Mangesh

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/hEnpm02gqJgJ.

To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Reply all
Reply to author
Forward
0 new messages