{"id":135,"date":"2007-04-12T00:38:00","date_gmt":"2007-04-12T00:38:00","guid":{"rendered":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/"},"modified":"2007-04-12T00:38:00","modified_gmt":"2007-04-12T00:38:00","slug":"c-java-native-interface-jni","status":"publish","type":"post","link":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/","title":{"rendered":"C++, Java Native Interface (JNI)"},"content":{"rendered":"<p>In my recent Java Native Interface (JNI) adventures, I have discovered that when calling the JNI function NewObject in C++, you need to cast the variables to their corresponding jni type. I didn&#8217;t have to do this when using C and jni.<br \/>Example:<br \/>C++ struct ABC { double x, double y };<\/p>\n<p>Using C++ create a jni object to pass to java:<\/p>\n<p>jobject createABC( JNIEnv* env, jobject obj )<br \/>{<br \/>  ABC abc;<br \/>  a.x = 5.2;<br \/>  a.y = 2.4;<\/p>\n<p>  jclass cls = env->FindClass( &#8220;ABC&#8221; ); \/\/ find the java ABC class<\/p>\n<p>  jmethodID mid = env->GetMethodID( cls, &#8220;<init>&#8220;, &#8220;(DD)V&#8221; );<\/p>\n<p>  jobject jabc = env->NewObject( cls, mid, (jdouble)a.x, (jdouble)a.y);<\/p>\n<p>  return jabc;<br \/>}<\/p>\n<p><a href=\"http:\/\/amy1975.bugdoctor.hop.clickbank.net\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" style=\"display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif\" border=\"0\" alt=\"Error Doctor 2007 ***Brand New 2007 Version! <br \/>&#8220;id=&#8221;BLOGGER_PHOTO_ID_5052354926391138034&#8221; \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my recent Java Native Interface (JNI) adventures, I have discovered that when calling the JNI function NewObject in C++, you need to cast the variables to their corresponding jni type. I didn&#8217;t have to do this when using C and jni.Example:C++ struct ABC { double x, double y }; Using C++ create a jni [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[288,289,287],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-c","category-casting","category-java-native-interface-jni"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++, Java Native Interface (JNI) - Zofxare Blog Home<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++, Java Native Interface (JNI) - Zofxare Blog Home\" \/>\n<meta property=\"og:description\" content=\"In my recent Java Native Interface (JNI) adventures, I have discovered that when calling the JNI function NewObject in C++, you need to cast the variables to their corresponding jni type. I didn&#8217;t have to do this when using C and jni.Example:C++ struct ABC { double x, double y }; Using C++ create a jni [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/\" \/>\n<meta property=\"og:site_name\" content=\"Zofxare Blog Home\" \/>\n<meta property=\"article:published_time\" content=\"2007-04-12T00:38:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif\" \/>\n<meta name=\"author\" content=\"zofxare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"zofxare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/\"},\"author\":{\"name\":\"zofxare\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"headline\":\"C++, Java Native Interface (JNI)\",\"datePublished\":\"2007-04-12T00:38:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/\"},\"wordCount\":109,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blogger.googleusercontent.com\\\/img\\\/b\\\/R29vZ2xl\\\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\\\/s400\\\/error_doctor.gif\",\"articleSection\":[\"C++\",\"casting\",\"Java Native Interface (JNI)\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/\",\"name\":\"C++, Java Native Interface (JNI) - Zofxare Blog Home\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blogger.googleusercontent.com\\\/img\\\/b\\\/R29vZ2xl\\\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\\\/s400\\\/error_doctor.gif\",\"datePublished\":\"2007-04-12T00:38:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#primaryimage\",\"url\":\"https:\\\/\\\/blogger.googleusercontent.com\\\/img\\\/b\\\/R29vZ2xl\\\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\\\/s400\\\/error_doctor.gif\",\"contentUrl\":\"https:\\\/\\\/blogger.googleusercontent.com\\\/img\\\/b\\\/R29vZ2xl\\\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\\\/s400\\\/error_doctor.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/04\\\/12\\\/c-java-native-interface-jni\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++, Java Native Interface (JNI)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\",\"name\":\"Zofxare Blog Home\",\"description\":\"The Zofxare blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\",\"name\":\"zofxare\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"caption\":\"zofxare\"},\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/author\\\/zofxare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++, Java Native Interface (JNI) - Zofxare Blog Home","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/","og_locale":"en_US","og_type":"article","og_title":"C++, Java Native Interface (JNI) - Zofxare Blog Home","og_description":"In my recent Java Native Interface (JNI) adventures, I have discovered that when calling the JNI function NewObject in C++, you need to cast the variables to their corresponding jni type. I didn&#8217;t have to do this when using C and jni.Example:C++ struct ABC { double x, double y }; Using C++ create a jni [&hellip;]","og_url":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/","og_site_name":"Zofxare Blog Home","article_published_time":"2007-04-12T00:38:00+00:00","og_image":[{"url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif","type":"","width":"","height":""}],"author":"zofxare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"zofxare","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#article","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/"},"author":{"name":"zofxare","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"headline":"C++, Java Native Interface (JNI)","datePublished":"2007-04-12T00:38:00+00:00","mainEntityOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/"},"wordCount":109,"commentCount":0,"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#primaryimage"},"thumbnailUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif","articleSection":["C++","casting","Java Native Interface (JNI)"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/","url":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/","name":"C++, Java Native Interface (JNI) - Zofxare Blog Home","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#primaryimage"},"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#primaryimage"},"thumbnailUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif","datePublished":"2007-04-12T00:38:00+00:00","author":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"breadcrumb":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#primaryimage","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif","contentUrl":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEhDSyEuZ7KeKa9w1bvLrZ392F1fVjJPO5UEd55XOtgnZxXUmUu-i3aIx28iagSyKCgYodEsllZgD570-uSo1heK6K94fEKwzPV-US0NqetCAJ-UYq6WeM8x9o7RpUts3eXG6tPr5OIpofS8\/s400\/error_doctor.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/04\/12\/c-java-native-interface-jni\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zofxare.com\/zofxare\/blog\/"},{"@type":"ListItem","position":2,"name":"C++, Java Native Interface (JNI)"}]},{"@type":"WebSite","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website","url":"https:\/\/zofxare.com\/zofxare\/blog\/","name":"Zofxare Blog Home","description":"The Zofxare blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zofxare.com\/zofxare\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce","name":"zofxare","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","caption":"zofxare"},"url":"https:\/\/zofxare.com\/zofxare\/blog\/author\/zofxare\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":0,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}