{"id":2919,"date":"2014-03-10T12:39:36","date_gmt":"2014-03-10T12:39:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/android-calling-java-class-from-c-native-activity-collection-of-common-programming-errors\/"},"modified":"2014-03-10T12:39:36","modified_gmt":"2014-03-10T12:39:36","slug":"android-calling-java-class-from-c-native-activity-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/android-calling-java-class-from-c-native-activity-collection-of-common-programming-errors\/","title":{"rendered":"Android: calling Java class from C++ Native Activity-Collection of common programming errors"},"content":{"rendered":"<p>Not sure what is causing your error (you do not indicate where the lines are, or the particular line where you are having difficulty debugging), but I will go ahead and point out a few quick mistakes I see.<\/p>\n<p>One first mistake is you need to use <code>CallStaticObjectMethod<\/code> since you are calling a static method. Your <code>jmethodid findClass<\/code> has a methodID, not a class, which is misleading and wrong. You also have two parameters, but you seem to be only passing one parameter.<\/p>\n<p>Basically, you need:<\/p>\n<p><code>(env)-&gt;GetStaticMethodID(jclass,\"method name\", \"Parameter list\")<\/code><\/p>\n<p>&#8211;jclass is the class reference &#8211;&#8220;method name&#8221; is the name of the method IN quotes &#8211;&#8220;Parameter list&#8221; is the list of parameters, which you need to look up syntax.<\/p>\n<p>Skipping a few things&#8230;To call your stuff you need:<\/p>\n<p><code>(env)-&gt;CallStaticObjectMethod(jclass,jmid,parameter1,parameter2)<\/code><\/p>\n<p>&#8211;jclass is once again the class that has the static method. &#8211;jmid is the java method id which you get from the function above. &#8211;parameter1 and parameter2 are the parameters required for the java method.<\/p>\n<p>Lastly, I think this may just be preference, but I would not attach the thread to the JVM until you have all the necessary information to make the jump into the JVM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not sure what is causing your error (you do not indicate where the lines are, or the particular line where you are having difficulty debugging), but I will go ahead and point out a few quick mistakes I see. One first mistake is you need to use CallStaticObjectMethod since you are calling a static method. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2919","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2919","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2919"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2919\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}