Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. public class BigDecimalDemo {
  3.  
  4. public static BigDecimal sum(BigDecimal d,String s , BigDecimal b) {
  5. BigDecimal ans1 = (d.add(b));
  6. System.out.println("result inside BigDecimalDemo = "+ans1);
  7. return ans1;
  8. }
  9. to call it i use below approch but not able to call the java method :
  10. int main(int argc, char* argv[])
  11. {
  12. JNIEnv *env;
  13. string result_op = " " ;
  14. JavaVM * jvm;
  15. env = create_vm(&jvm);
  16. int i ;
  17. if (env == NULL)
  18. return 1;
  19. jclass clsH , ClsB =NULL;
  20. jmethodID midBigD , midMain = NULL;
  21. ClsB = env->FindClass("java/math/BigDecimal"); // for bigdecimal object
  22. clsH = env->FindClass("com/fedex/test"); // for my class
  23. midMain = env->GetMethodID(clsH, "sum", "(Ljava/math/BigDecimal;Ljava/lang/String;Ljava/math/BigDecimal)Ljava/math/BigDecimal");
  24. midBigD = env->GetMethodID(ClsB, "<init>", "(D)V");
  25. jobject bd1 = env->NewObject(ClsB, midBigD, 12.1234);
  26. jobject bd2 = env->NewObject(ClsB, midBigD , 0.0500);
  27. jstring StringArg2 = env->NewStringUTF("STD");
  28. jobject result = env->CallObjectMethod(clsH, midMain,bd1,StringArg2,bd2 ); //Calling the method.
  29. printf(" print the resultn ");
  30. //Release resources.
  31. int n = jvm->DestroyJavaVM();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement