{"id":196,"date":"2024-09-20T23:06:57","date_gmt":"2024-09-20T15:06:57","guid":{"rendered":"https:\/\/newstrong.xyz\/?p=196"},"modified":"2024-09-20T23:06:57","modified_gmt":"2024-09-20T15:06:57","slug":"findclass-from-any-thread-in-android-jni","status":"publish","type":"post","link":"https:\/\/newstrong.top\/index.php\/2024\/09\/20\/findclass-from-any-thread-in-android-jni\/","title":{"rendered":"FindClass from any thread in Android JNI"},"content":{"rendered":"<div class=\"question js-question\" data-questionid=\"13263340\" data-position-on-page=\"0\" data-score=\"53\" id=\"question\">\n<style>\n    <\/style>\n<div class=\"js-zone-container zone-container-main\">\n<div id=\"dfp-tlb\" class=\"everyonelovesstackoverflow everyoneloves__top-leaderboard everyoneloves__leaderboard\"><\/div>\n<div class=\"js-report-ad-button-container \" style=\"width: 728px\"><\/div>\n<\/div>\n<div class=\"post-layout \">\n<div class=\"postcell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Android&#8217;s JNI tips page mentions this <a href=\"http:\/\/developer.android.com\/guide\/practices\/jni.html#faq_FindClass\" rel=\"noreferrer\">FAQ: Why didn&#8217;t FindClass find my class?<\/a><br \/>\nThey mention multiple solutions and the last option there is this one:<\/p>\n<blockquote>\n<p>Cache a reference to the ClassLoader object somewhere handy, and issue<br \/>\n  loadClass calls directly. This requires some effort.<\/p>\n<\/blockquote>\n<p>So, I tried to get it working and it seems that no matter what, this method simply does not work for me. Eventually, I figured how to use ClassLoader but it won&#8217;t work if from a native thread I try to loadClass that hasn&#8217;t been touched\/loaded yet. Essentially, it&#8217;s the identical to env-&gt;FindClass in behavior when called from a native thread, with the exception that it won&#8217;t return 0 for classes that were already use in the app. Any idea if I didn&#8217;t get it right, or it&#8217;s impossible to access classes from a native thread that weren&#8217;t used\/loaded yet.<\/p>\n<p>\n<strong>EDIT:<\/strong> I&#8217;ll give more info to explain what exactly I mean. There is regular JNI <code>env-&gt;FindClass(className)<\/code>, and another one that I wrote <code>myFindClass(env, className)<\/code> that uses cached <code>ClassLoader-&gt;loadClass<\/code>.<\/p>\n<p>The class that I&#8217;m trying to access from native c\/c++ is &#8220;com\/noname\/TestClient&#8221;. Inside myFindClass I also use env-&gt;FindClass and log value that it returns:<\/p>\n<pre><code>jclass myFindClass(JNIEnv * env, const char* name)\n{\n    ...\n    jclass c0 = env-&gt;FindClass(name);\n    jclass c1 = (jclass)env-&gt;CallObjectMethod(ClassLoader,\n        MID_loadClass, envNewStringUTF(name));\n    dlog(\"myFindClass(\"%s\") =&gt; c0:%p, c1:%p, c0 and c1 are same: %d\",\n        name, c0, c1, env-&gt;IsSameObject(c0, c1));\n    ...\n}\n<\/code><\/pre>\n<p>Then, I have these 3 combinations to explain the issue.<\/p>\n<p><strong>1)<\/strong><\/p>\n<pre><code>\/\/inside JNI_OnLoad thread\nmyFindClass(env, \"com\/noname\/TestClient\");\n...\n\n\/\/inside native thread created by pthread_create\nmyFindClass(env, \"com\/noname\/TestClient\");\n<\/code><\/pre>\n<p>I get this logcat:<\/p>\n<blockquote>\n<p>myFindClass(&#8220;com\/noname\/TestClent&#8221;) =&gt; c0:0x41b64558, c1:0x41b64558,<br \/>\n  c0 and c1 are same: 1 <br \/>&#8230;<br \/>myFindClass(&#8220;com\/noname\/TestClent&#8221;) =&gt; c0:0,<br \/>\n  c1:0x41b64558, c0 and c1 are same: 0<\/p>\n<\/blockquote>\n<p><strong>2)<\/strong><\/p>\n<pre><code>\/\/inside JNI_OnLoad thread\nenv-&gt;FindClass(\"com\/noname\/TestClient\");\n...\n\n\/\/inside native thread created by pthread_create\nmyFindClass(\"com\/noname\/TestClient\");\n<\/code><\/pre>\n<p>I get this logcat:<\/p>\n<blockquote>\n<p>myFindClass(&#8220;com\/noname\/TestClent&#8221;) =&gt; c0:0, c1:0x41b64558, c0 and c1 are same: 0<\/p>\n<\/blockquote>\n<p><strong>3)<\/strong><\/p>\n<pre><code>\/\/inside JNI_OnLoad thread\n\/\/\"com\/noname\/TestClient\" isn't touched from JNI_OnLoad.\n...\n\n\/\/inside native thread created by pthread_create\nmyFindClass(env, \"com\/noname\/TestClient\");\n<\/code><\/pre>\n<p>I get this logcat:<\/p>\n<blockquote>\n<p>myFindClass(&#8220;com\/noname\/TestClent&#8221;) =&gt; c0:0, c1:0, c0 and c1 are same: 1<\/p>\n<\/blockquote>\n<p>Basically, my issue is that ClassLoader doesn&#8217;t find my class in the 3rd case. Is it a bug? What can be done to fix the problem?<\/p>\n<p><strong>EDIT2:<\/strong><br \/>\nOn top of that, it seems that ClassLoader::loadClass is plainly buggy. If I ask myFindClass(&#8220;noname\/TestClent&#8221;) then it returns some garbage, and when I use that returned jclass in any way the app crashes.<\/p>\n<\/p><\/div>\n<div class=\"mt24 mb12\">\n<div class=\"post-taglist d-flex gs4 gsy fd-column\">\n<div class=\"d-flex ps-relative fw-wrap\">\n                    <a class=\"themed subcommunity-topic-avatar subcommunity-topic-mobile-dev s-avatar s-avatar__24 mr2 js-community-tag my2 mr6 va-top\" style=\"\" data-controller=\"s-tooltip\" title=\"Mobile Development Collective\" href=\"https:\/\/stackoverflow.com\/collectives\/mobile-dev\"><\/a><\/p>\n<ul class=\"ml0 list-ls-none js-post-tag-list-wrapper d-inline\">\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/android\" class=\"s-tag post-tag\" title=\"show questions tagged 'android'\" aria-label=\"show questions tagged 'android'\" rel=\"tag\" aria-labelledby=\"tag-android-tooltip-container\" data-tag-menu-origin=\"Unknown\">android<\/a><\/li>\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/c%2b%2b\" class=\"s-tag post-tag\" title=\"show questions tagged 'c++'\" aria-label=\"show questions tagged 'c++'\" rel=\"tag\" aria-labelledby=\"tag-c++-tooltip-container\" data-tag-menu-origin=\"Unknown\">c++<\/a><\/li>\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/java-native-interface\" class=\"s-tag post-tag\" title=\"show questions tagged 'java-native-interface'\" aria-label=\"show questions tagged 'java-native-interface'\" rel=\"tag\" aria-labelledby=\"tag-java-native-interface-tooltip-container\" data-tag-menu-origin=\"Unknown\">java-native-interface<\/a><\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"mb0 \">\n<div class=\"mt16 d-flex gs8 gsy fw-wrap jc-end ai-start pt4 mb16\">\n<div class=\"flex--item mr16 fl1 w96\">\n<div class=\"js-post-menu pt2\" data-post-id=\"13263340\" data-post-type-id=\"1\">\n<div class=\"d-flex gs8 s-anchors s-anchors__muted fw-wrap\">\n<div class=\"flex--item\">\n            <a href=\"https:\/\/stackoverflow.com\/q\/13263340\" rel=\"nofollow\" itemprop=\"url\" class=\"js-share-link js-gps-track\" title=\"Short permalink to this question\" data-gps-track=\"post.click({ item: 2, priv: 0, post_type: 1 })\" data-controller=\"se-share-sheet\" data-se-share-sheet-title=\"Share a link to this question\" data-se-share-sheet-subtitle=\"\" data-se-share-sheet-post-type=\"question\" data-se-share-sheet-social=\"facebook twitter devto\" data-se-share-sheet-location=\"1\" data-se-share-sheet-license-url=\"https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f\" data-se-share-sheet-license-name=\"CC BY-SA 3.0\" data-s-popover-placement=\"bottom-start\">Share<\/a>\n        <\/div>\n<div class=\"flex--item\">\n                    <button type=\"button\" id=\"btnFollowPost-13263340\" class=\"s-btn s-btn__link js-follow-post js-follow-question js-gps-track\" data-gps-track=\"post.click({ item: 14, priv: 0, post_type: 1 })\" data-controller=\"s-tooltip \" data-s-tooltip-placement=\"bottom\" data-s-popover-placement=\"bottom\" aria-controls=\"\" title=\"Follow this question to receive notifications\"><br \/>\n                        Follow<br \/>\n                        <input type=\"hidden\" id=\"voteFollowHash\" value=\"70:3:31e,16:1bac6f9ebd790310,10:1726842606,16:d6a6fa6cef041b29,8:13263340,85507e7147e76045ef8aed069b6da7cb3fc73f826e1c345cd44378f2ba7ca38b\"><br \/>\n                    <\/button>\n                <\/div>\n<\/p><\/div>\n<div class=\"js-menu-popup-container\"><\/div>\n<\/div><\/div>\n<div class=\"post-signature flex--item\">\n<div class=\"user-info \">\n<div class=\"d-flex \">\n<div class=\"user-action-time fl-grow1\">\n            <a href=\"https:\/\/stackoverflow.com\/posts\/13263340\/revisions\" title=\"show all edits to this post\" class=\"js-gps-track\" data-gps-track=\"post.click({ item: 4, priv: 0, post_type: 1 })\">edited <span title=\"2012-11-07 07:56:06Z\" class=\"relativetime\">Nov 7, 2012 at 7:56<\/span><\/a>\n        <\/div>\n<\/p><\/div>\n<div class=\"user-gravatar32\"><\/div>\n<div class=\"user-details\" itemprop=\"author\" itemscope itemtype=\"http:\/\/schema.org\/Person\">\n        <span class=\"d-none\" itemprop=\"name\">Pavel P<\/span><\/p>\n<div class=\"-flair\"><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"post-signature owner flex--item\">\n<div class=\"user-info \">\n<div class=\"d-flex \">\n<div class=\"user-action-time fl-grow1\">\n            asked <span title=\"2012-11-07 04:56:51Z\" class=\"relativetime\">Nov 7, 2012 at 4:56<\/span>\n        <\/div>\n<\/p><\/div>\n<div class=\"user-gravatar32\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/468725\/pavel-p\"><\/p>\n<div class=\"gravatar-wrapper-32\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gravatar.com\/avatar\/85a49cd89084e6512dee0f140e86d5b4?s=64&amp;d=identicon&amp;r=PG\" alt=\"Pavel P's user avatar\" width=\"32\" height=\"32\" class=\"bar-sm\"><\/div>\n<p><\/a>\n    <\/div>\n<div class=\"user-details\" itemprop=\"author\" itemscope itemtype=\"http:\/\/schema.org\/Person\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/468725\/pavel-p\">Pavel P<\/a><span class=\"d-none\" itemprop=\"name\">Pavel P<\/span><\/p>\n<div class=\"-flair\">\n            <span class=\"reputation-score\" title=\"reputation score 16,619\" dir=\"ltr\">16.6k<\/span><span title=\"11 gold badges\" aria-hidden=\"true\"><span class=\"badge1\"><\/span><span class=\"badgecount\">11<\/span><\/span><span class=\"v-visible-sr\">11 gold badges<\/span><span title=\"86 silver badges\" aria-hidden=\"true\"><span class=\"badge2\"><\/span><span class=\"badgecount\">86<\/span><\/span><span class=\"v-visible-sr\">86 silver badges<\/span><span title=\"137 bronze badges\" aria-hidden=\"true\"><span class=\"badge3\"><\/span><span class=\"badgecount\">137<\/span><\/span><span class=\"v-visible-sr\">137 bronze badges<\/span>\n        <\/div>\n<\/p><\/div>\n<\/div><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">3<\/span> <\/p>\n<div class=\"post-layout--right js-post-comments-component\">\n<div id=\"comments-13263340\" class=\"comments js-comments-container bt bc-black-200 mt12 \" data-post-id=\"13263340\" data-min-length=\"15\">\n<ul class=\"comments-list js-comments-list\" data-remaining-comments-count=\"0\" data-canpost=\"false\" data-cansee=\"true\" data-comments-unavailable=\"false\" data-addlink-disabled=\"true\">\n<li id=\"comment-18088078\" class=\"comment js-comment \" data-comment-id=\"18088078\" data-comment-owner-id=\"523744\" data-comment-score=\"0\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">Yes, that&#8217;s normal, Android apps do not use the system class loader by default. Just cache all that you need in <code>JNI_OnLoad()<\/code> and that will take care of that.<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/523744\/samuel-audet\" title=\"4,994 reputation\" class=\"comment-user\">Samuel Audet<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2012-11-07 13:24:37Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">Nov 7, 2012 at 13:24<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-23624802\" class=\"comment js-comment \" data-comment-id=\"23624802\" data-comment-owner-id=\"294248\" data-comment-score=\"1\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"cool\">1<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">Re: EDIT2: sounds like the method threw an exception, at which point the return value is undefined.  <code>loadClass()<\/code> never returns null; it either returns the class reference or it throws an exception.<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/294248\/fadden\" title=\"52,155 reputation\" class=\"comment-user\">fadden<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-05-09 16:39:38Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">May 9, 2013 at 16:39<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-23630300\" class=\"comment js-comment \" data-comment-id=\"23630300\" data-comment-owner-id=\"468725\" data-comment-score=\"0\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">@fadden it could be. I don&#8217;t remember exactly what was the issue, but I solved it eventually.<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/468725\/pavel-p\" title=\"16,619 reputation\" class=\"comment-user owner\">Pavel P<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-05-09 19:41:59Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">May 9, 2013 at 19:41<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<\/ul><\/div>\n<div id=\"comments-link-13263340\" data-rep=\"50\" data-anon=\"true\">\n                    <a class=\"js-add-link comments-link disabled-link\" title=\"Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.\" href=\"\" role=\"button\">Add a comment<\/a><br \/>\n                <span class=\"js-link-separator dno\">\u00a0|\u00a0<\/span><br \/>\n            <a class=\"js-show-link comments-link dno\" title=\"Expand to show all comments on this post\" href=\"\" onclick=\"\" role=\"button\"><\/a>\n        <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"js-zone-container zone-container-responsive\">\n<div id=\"dfp-isb\" class=\"everyonelovesstackoverflow everyoneloves__inline-sidebar mx-auto\"><\/div>\n<div class=\"js-report-ad-button-container mx-auto\" style=\"width: 300px\"><\/div>\n<\/div>\n<pre><code>            <div id=\"answers\">\n                <a name=\"tab-top\"><\/a>\n                <div id=\"answers-header\">\n                    <div class=\"answers-subheader d-flex ai-center mb8\">\n                        <div class=\"flex--item fl1\">\n                            <h2 class=\"mb0\" data-answercount=\"2\">\n                                    2 Answers\n                                <span style=\"display:none;\" itemprop=\"answerCount\">2<\/span>\n                            <\/h2>\n                        <\/div>\n                        <div class=\"flex--item\"><\/code><\/pre>\n<div class=\"d-flex g4 gsx ai-center sm:fd-column sm:ai-start\">\n<div class=\"d-flex fd-column ai-end sm:ai-start\">\n        <label class=\"flex--item fs-caption\" for=\"answer-sort-dropdown-select-menu\"><br \/>\n            Sorted by:<br \/>\n        <\/label><br \/>\n        <a class=\"js-sort-preference-change s-link flex--item fs-fine d-none\" data-value=\"ScoreDesc\" href=\"https:\/\/stackoverflow.com\/questions\/13263340\/findclass-from-any-thread-in-android-jni?answertab=scoredesc#tab-top\"><br \/>\n            Reset to default<br \/>\n        <\/a>\n    <\/div>\n<div class=\"flex--item s-select\">\n        <select id=\"answer-sort-dropdown-select-menu\"><option value=\"scoredesc\" selected><br \/>\n                        Highest score (default)<br \/>\n                    <\/option><option value=\"trending\"><br \/>\n                        Trending (recent votes count more)<br \/>\n                    <\/option><option value=\"modifieddesc\"><br \/>\n                        Date modified (newest first)<br \/>\n                    <\/option><option value=\"createdasc\"><br \/>\n                        Date created (oldest first)<br \/>\n                    <\/option><\/select>\n    <\/div>\n<\/div>\n<pre><code>                        <\/div>\n                    <\/div>\n\n                <\/div><\/code><\/pre>\n<p><a name=\"16302771\"><\/a><\/p>\n<div id=\"answer-16302771\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"16302771\" data-parentid=\"13263340\" data-score=\"84\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"answercell post-layout--right\">\n<div class=\"js-endorsements\" data-for-answer=\"16302771\">\n<\/div>\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>After much trying and crashing of my app, a colleague and I managed to cache and succesfully use the class loader in another, native, thread. The code we used is shown below (C++11, but easily converted to C++2003), posted here since we couldn&#8217;t find any examples of the aforementioned &#8220;Cache a reference to the ClassLoader object somewhere handy, and issue loadClass calls directly. This requires some effort.&#8221;. Calling findClass worked perfectly when called from a thread different from the one of JNI_OnLoad. I hope this helps.<\/p>\n<pre><code>JavaVM* gJvm = nullptr;\nstatic jobject gClassLoader;\nstatic jmethodID gFindClassMethod;\n\nJNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) {\n    gJvm = pjvm;  \/\/ cache the JavaVM pointer\n    auto env = getEnv();\n    \/\/replace with one of your classes in the line below\n    auto randomClass = env-&gt;FindClass(\"com\/example\/RandomClass\");\n    jclass classClass = env-&gt;GetObjectClass(randomClass);\n    auto classLoaderClass = env-&gt;FindClass(\"java\/lang\/ClassLoader\");\n    auto getClassLoaderMethod = env-&gt;GetMethodID(classClass, \"getClassLoader\",\n                                             \"()Ljava\/lang\/ClassLoader;\");\n    gClassLoader = env-&gt;CallObjectMethod(randomClass, getClassLoaderMethod);\n    gFindClassMethod = env-&gt;GetMethodID(classLoaderClass, \"findClass\",\n                                    \"(Ljava\/lang\/String;)Ljava\/lang\/Class;\");\n\n    return JNI_VERSION_1_6;\n}\n\njclass findClass(const char* name) {\n    return static_cast<jclass>(getEnv()-&gt;CallObjectMethod(gClassLoader, gFindClassMethod, getEnv()-&gt;NewStringUTF(name)));\n}\n\nJNIEnv* getEnv() {\n    JNIEnv *env;\n    int status = gJvm-&gt;GetEnv((void**)&amp;env, JNI_VERSION_1_6);\n    if(status &lt; 0) {    \n        status = gJvm-&gt;AttachCurrentThread(&amp;env, NULL);\n        if(status &lt; 0) {        \n            return nullptr;\n        }\n    }\n    return env;\n}\n<\/jclass><\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\">\n<div class=\"d-flex fw-wrap ai-start jc-end gs8 gsy\">\n            <time itemprop=\"dateCreated\" datetime=\"2013-04-30T14:47:42\"><\/time><\/p>\n<div class=\"flex--item mr16\" style=\"flex: 1 1 100px;\">\n<div class=\"js-post-menu pt2\" data-post-id=\"16302771\" data-post-type-id=\"2\">\n<div class=\"d-flex gs8 s-anchors s-anchors__muted fw-wrap\">\n<div class=\"flex--item\">\n            <a href=\"https:\/\/stackoverflow.com\/a\/16302771\" rel=\"nofollow\" itemprop=\"url\" class=\"js-share-link js-gps-track\" title=\"Short permalink to this answer\" data-gps-track=\"post.click({ item: 2, priv: 0, post_type: 2 })\" data-controller=\"se-share-sheet\" data-se-share-sheet-title=\"Share a link to this answer\" data-se-share-sheet-subtitle=\"\" data-se-share-sheet-post-type=\"answer\" data-se-share-sheet-social=\"facebook twitter devto\" data-se-share-sheet-location=\"2\" data-se-share-sheet-license-url=\"https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f\" data-se-share-sheet-license-name=\"CC BY-SA 3.0\" data-s-popover-placement=\"bottom-start\">Share<\/a>\n        <\/div>\n<div class=\"flex--item\">\n                    <button type=\"button\" id=\"btnFollowPost-16302771\" class=\"s-btn s-btn__link js-follow-post js-follow-answer js-gps-track\" data-gps-track=\"post.click({ item: 14, priv: 0, post_type: 2 })\" data-controller=\"s-tooltip \" data-s-tooltip-placement=\"bottom\" data-s-popover-placement=\"bottom\" aria-controls=\"\" title=\"Follow this answer to receive notifications\"><br \/>\n                        Follow<br \/>\n                        <input type=\"hidden\" id=\"voteFollowHash\" value=\"70:3:31e,16:fc1d16ebeb9cce52,10:1726842606,16:4da696b07a4f6344,8:16302771,0eca2d14c2c3df51bfe7f093268f722de92aedf4f9b03667115a848acf23251d\"><br \/>\n                    <\/button>\n                <\/div>\n<\/p><\/div>\n<div class=\"js-menu-popup-container\"><\/div>\n<\/div><\/div>\n<div class=\"post-signature flex--item fl0\">\n<div class=\"user-info user-hover \">\n<div class=\"d-flex \">\n<div class=\"user-action-time fl-grow1\">\n            <a href=\"https:\/\/stackoverflow.com\/posts\/16302771\/revisions\" title=\"show all edits to this post\" class=\"js-gps-track\" data-gps-track=\"post.click({ item: 4, priv: 0, post_type: 2 })\">edited <span title=\"2014-04-16 14:27:26Z\" class=\"relativetime\">Apr 16, 2014 at 14:27<\/span><\/a>\n        <\/div>\n<\/p><\/div>\n<div class=\"user-gravatar32\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/369009\/jan-r%c3%bcegg\"><\/p>\n<div class=\"gravatar-wrapper-32\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gravatar.com\/avatar\/001cc37902a582ddb930a1ab817517bc?s=64&amp;d=identicon&amp;r=PG\" alt=\"Jan R\u00fcegg's user avatar\" width=\"32\" height=\"32\" class=\"bar-sm\"><\/div>\n<p><\/a>\n    <\/div>\n<div class=\"user-details\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/369009\/jan-r%c3%bcegg\">Jan R\u00fcegg<\/a><\/p>\n<div class=\"-flair\">\n            <span class=\"reputation-score\" title=\"reputation score \" dir=\"ltr\">9,987<\/span><span title=\"8 gold badges\" aria-hidden=\"true\"><span class=\"badge1\"><\/span><span class=\"badgecount\">8<\/span><\/span><span class=\"v-visible-sr\">8 gold badges<\/span><span title=\"65 silver badges\" aria-hidden=\"true\"><span class=\"badge2\"><\/span><span class=\"badgecount\">65<\/span><\/span><span class=\"v-visible-sr\">65 silver badges<\/span><span title=\"111 bronze badges\" aria-hidden=\"true\"><span class=\"badge3\"><\/span><span class=\"badgecount\">111<\/span><\/span><span class=\"v-visible-sr\">111 bronze badges<\/span>\n        <\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"post-signature flex--item fl0\">\n<div class=\"user-info user-hover \">\n<div class=\"d-flex \">\n<div class=\"user-action-time fl-grow1\">\n            answered <span title=\"2013-04-30 14:47:42Z\" class=\"relativetime\">Apr 30, 2013 at 14:47<\/span>\n        <\/div>\n<\/p><\/div>\n<div class=\"user-gravatar32\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/828046\/%c3%81tila-neves\"><\/p>\n<div class=\"gravatar-wrapper-32\"><img decoding=\"async\" src=\"https:\/\/newstrong.xyz\/wp-content\/uploads\/2024\/09\/frc-201224e99d1c1519dc08dfa157884576.jpg\"><\/div>\n<p><\/a>\n    <\/div>\n<div class=\"user-details\" itemprop=\"author\" itemscope itemtype=\"http:\/\/schema.org\/Person\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/828046\/%c3%81tila-neves\">\u00c1tila Neves<\/a><span class=\"d-none\" itemprop=\"name\">\u00c1tila Neves<\/span><\/p>\n<div class=\"-flair\">\n            <span class=\"reputation-score\" title=\"reputation score \" dir=\"ltr\">1,412<\/span><span title=\"12 silver badges\" aria-hidden=\"true\"><span class=\"badge2\"><\/span><span class=\"badgecount\">12<\/span><\/span><span class=\"v-visible-sr\">12 silver badges<\/span><span title=\"14 bronze badges\" aria-hidden=\"true\"><span class=\"badge3\"><\/span><span class=\"badgecount\">14<\/span><\/span><span class=\"v-visible-sr\">14 bronze badges<\/span>\n        <\/div>\n<\/p><\/div>\n<\/div><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">15<\/span> <\/p>\n<div class=\"post-layout--right js-post-comments-component\">\n<div id=\"comments-16302771\" class=\"comments js-comments-container bt bc-black-200 mt12 \" data-post-id=\"16302771\" data-min-length=\"15\">\n<ul class=\"comments-list js-comments-list\" data-remaining-comments-count=\"10\" data-canpost=\"false\" data-cansee=\"true\" data-comments-unavailable=\"false\" data-addlink-disabled=\"true\">\n<li id=\"comment-23624748\" class=\"comment js-comment \" data-comment-id=\"23624748\" data-comment-owner-id=\"294248\" data-comment-score=\"7\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"warm\">7<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\"><code>ClassLoader.loadClass()<\/code> does not return null when the class is not found.  It throws an exception, which means the return value is undefined.  You must check for exceptions after calling <code>CallObjectMethod<\/code>, and you must not use the return value if an exception has been raised.  (This is true in general &#8212; any <code>Call*Method<\/code> invocation should be followed by <code>ExceptionCheck<\/code> or <code>ExceptionOccurred<\/code>, and you can see the exception in the log with <code>ExceptionDescribe<\/code>.)<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/294248\/fadden\" title=\"52,155 reputation\" class=\"comment-user\">fadden<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-05-09 16:37:07Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">May 9, 2013 at 16:37<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-23731898\" class=\"comment js-comment \" data-comment-id=\"23731898\" data-comment-owner-id=\"294248\" data-comment-score=\"6\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"warm\">6<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">I understand; I just wanted to make sure that anybody who did copy it added the necessary checks to <code>JNI_OnLoad<\/code> and <code>findClass<\/code> (especially the latter &#8212; you could convert an exception to NULL there, and clear the exception, to get the semantics you want).  Note also you don&#8217;t need to call <code>FindClass<\/code> to find <code>java.lang.Class<\/code>; you can just use <code>GetObjectClass<\/code> on the <code>jclass<\/code> you already have (it&#8217;s faster and never fails on a valid object).  Have you tried this on Android &gt;= 4.0?  Looks like you need a <code>NewGlobalRef<\/code> on <code>gFindClassMethod<\/code>.<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/294248\/fadden\" title=\"52,155 reputation\" class=\"comment-user\">fadden<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-05-13 16:35:51Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">May 13, 2013 at 16:35<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-24207272\" class=\"comment js-comment \" data-comment-id=\"24207272\" data-comment-owner-id=\"294248\" data-comment-score=\"1\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"cool\">1<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">Cool.  FWIW, I meant gClassLoader &#8212; gFindClassMethod is a jmethodID.<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/294248\/fadden\" title=\"52,155 reputation\" class=\"comment-user\">fadden<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-05-28 16:32:51Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">May 28, 2013 at 16:32<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-28022267\" class=\"comment js-comment \" data-comment-id=\"28022267\" data-comment-owner-id=\"1294646\" data-comment-score=\"14\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"warm\">14<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">Excelent answer&#8230; Just a comment, this didn&#8217;t worked for me because of this : <a href=\"http:\/\/stackoverflow.com\/questions\/14765776\/jni-error-app-bug-accessed-stale-local-reference-0xbc00021-index-8-in-a-tabl\" title=\"jni error app bug accessed stale local reference 0xbc00021 index 8 in a tabl\">stackoverflow.com\/questions\/14765776\/\u2026<\/a>. After calling NewGlobalRef() on the gClassLoader object, this solved my problem. Thanks!<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/1294646\/larrypel\" title=\"286 reputation\" class=\"comment-user\">LarryPel<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2013-09-24 02:22:05Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">Sep 24, 2013 at 2:22<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<li id=\"comment-54044934\" class=\"comment js-comment \" data-comment-id=\"54044934\" data-comment-owner-id=\"363177\" data-comment-score=\"7\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"warm\">7<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">thanks for the solution. note you have to call <code>NewGlobalRef()<\/code> BEFORE this gets stored globally. calling <code>NewGlobalRef()<\/code> from a different thread isn&#8217;t going to work. Do it like such:         <code>gClassLoader = env-&gt;NewGlobalRef(env-&gt;CallObjectMethod(myClass, getClassLoaderMethod));<\/code>  For more details check here: <a href=\"http:\/\/android-developers.blogspot.kr\/2011\/11\/jni-local-reference-changes-in-ics.html\" rel=\"nofollow noreferrer\">android-developers.blogspot.kr\/2011\/11\/\u2026<\/a><\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/363177\/andy-matteson\" title=\"368 reputation\" class=\"comment-user\">Andy Matteson<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2015-10-14 02:00:09Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">Oct 14, 2015 at 2:00<\/span><br \/>\n                <\/span><br \/>\n                        <span title=\"this comment was edited 3 times\"><br \/>\n                            <svg aria-hidden=\"true\" class=\"va-text-bottom o50 svg-icon iconPencilSm\" width=\"14\" height=\"14\" viewbox=\"0 0 14 14\"><path fill=\"#F1B600\" d=\"m2 10.12 6.37-6.43 1.88 1.88L3.88 12H2z\"><\/path><path fill=\"#E87C87\" d=\"m11.1 1.71 1.13 1.12c.2.2.2.51 0 .71L11.1 4.7 9.21 2.86l1.17-1.15c.2-.2.51-.2.71 0\"><\/path><\/svg><br \/>\n                        <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<\/ul><\/div>\n<div id=\"comments-link-16302771\" data-rep=\"50\" data-anon=\"true\">\n                    <a class=\"js-add-link comments-link dno\" title=\"Use comments to ask for more information or suggest improvements. Avoid comments like \u201c+1\u201d or \u201cthanks\u201d.\" href=\"\" role=\"button\"><\/a><br \/>\n                <span class=\"js-link-separator dno\">\u00a0|\u00a0<\/span><br \/>\n            <a class=\"js-show-link comments-link \" title=\"Expand to show all comments on this post\" href=\"\" onclick=\"\" role=\"button\">Show <b>10<\/b> more comments<\/a>\n        <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"js-zone-container zone-container-main\">\n<div id=\"dfp-mlb\" class=\"everyonelovesstackoverflow everyoneloves__mid-leaderboard everyoneloves__leaderboard\"><\/div>\n<div class=\"js-report-ad-button-container \" style=\"width: 728px\"><\/div>\n<\/div>\n<p><a name=\"13264184\"><\/a><\/p>\n<div id=\"answer-13264184\" class=\"answer js-answer\" data-answerid=\"13264184\" data-parentid=\"13263340\" data-score=\"5\" data-position-on-page=\"2\" data-highest-scored=\"0\" data-question-has-accepted-highest-score=\"1\" itemprop=\"suggestedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"answercell post-layout--right\">\n<div class=\"js-endorsements\" data-for-answer=\"13264184\">\n<\/div>\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Try attaching your native thread to the JVM first. <\/p>\n<p>The pointer to jvm you can obtain first thing in <code>JNI_OnLoad<\/code><\/p>\n<pre><code>env-&gt;GetJavaVM(&amp;jvm);\n<\/code><\/pre>\n<p>Then from your native thread<\/p>\n<pre><code>JNIEnv *env;\njvm-&gt;AttachCurrentThread((void **)&amp;env, NULL);\n<\/code><\/pre>\n<p>Then use that <code>env<\/code> for <code>FindClass<\/code><\/p>\n<\/p><\/div>\n<div class=\"mt24\">\n<div class=\"d-flex fw-wrap ai-start jc-end gs8 gsy\">\n            <time itemprop=\"dateCreated\" datetime=\"2012-11-07T06:20:42\"><\/time><\/p>\n<div class=\"flex--item mr16\" style=\"flex: 1 1 100px;\">\n<div class=\"js-post-menu pt2\" data-post-id=\"13264184\" data-post-type-id=\"2\">\n<div class=\"d-flex gs8 s-anchors s-anchors__muted fw-wrap\">\n<div class=\"flex--item\">\n            <a href=\"https:\/\/stackoverflow.com\/a\/13264184\" rel=\"nofollow\" itemprop=\"url\" class=\"js-share-link js-gps-track\" title=\"Short permalink to this answer\" data-gps-track=\"post.click({ item: 2, priv: 0, post_type: 2 })\" data-controller=\"se-share-sheet\" data-se-share-sheet-title=\"Share a link to this answer\" data-se-share-sheet-subtitle=\"\" data-se-share-sheet-post-type=\"answer\" data-se-share-sheet-social=\"facebook twitter devto\" data-se-share-sheet-location=\"2\" data-se-share-sheet-license-url=\"https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f\" data-se-share-sheet-license-name=\"CC BY-SA 3.0\" data-s-popover-placement=\"bottom-start\">Share<\/a>\n        <\/div>\n<div class=\"flex--item\">\n                    <button type=\"button\" id=\"btnFollowPost-13264184\" class=\"s-btn s-btn__link js-follow-post js-follow-answer js-gps-track\" data-gps-track=\"post.click({ item: 14, priv: 0, post_type: 2 })\" data-controller=\"s-tooltip \" data-s-tooltip-placement=\"bottom\" data-s-popover-placement=\"bottom\" aria-controls=\"\" title=\"Follow this answer to receive notifications\"><br \/>\n                        Follow<br \/>\n                        <input type=\"hidden\" id=\"voteFollowHash\" value=\"70:3:31e,16:4f7a48a69ab79334,10:1726842606,16:1905b36b16025154,8:13264184,8ab01b76eba28ee63b359d56af26fc36108164859fcbf7adff24a82e004ead0d\"><br \/>\n                    <\/button>\n                <\/div>\n<\/p><\/div>\n<div class=\"js-menu-popup-container\"><\/div>\n<\/div><\/div>\n<div class=\"post-signature flex--item fl0\">\n<div class=\"user-info \">\n<div class=\"d-flex \">\n<div class=\"user-action-time fl-grow1\">\n            answered <span title=\"2012-11-07 06:20:42Z\" class=\"relativetime\">Nov 7, 2012 at 6:20<\/span>\n        <\/div>\n<\/p><\/div>\n<div class=\"user-gravatar32\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/721079\/alexander\"><\/p>\n<div class=\"gravatar-wrapper-32\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gravatar.com\/avatar\/797c7fdac4c3c4836b61e09c2943c09d?s=64&amp;d=identicon&amp;r=PG\" alt=\"Alexander's user avatar\" width=\"32\" height=\"32\" class=\"bar-sm\"><\/div>\n<p><\/a>\n    <\/div>\n<div class=\"user-details\" itemprop=\"author\" itemscope itemtype=\"http:\/\/schema.org\/Person\">\n        <a href=\"https:\/\/stackoverflow.com\/users\/721079\/alexander\">Alexander<\/a><span class=\"d-none\" itemprop=\"name\">Alexander<\/span><\/p>\n<div class=\"-flair\">\n            <span class=\"reputation-score\" title=\"reputation score 48,172\" dir=\"ltr\">48.2k<\/span><span title=\"40 gold badges\" aria-hidden=\"true\"><span class=\"badge1\"><\/span><span class=\"badgecount\">40<\/span><\/span><span class=\"v-visible-sr\">40 gold badges<\/span><span title=\"108 silver badges\" aria-hidden=\"true\"><span class=\"badge2\"><\/span><span class=\"badgecount\">108<\/span><\/span><span class=\"v-visible-sr\">108 silver badges<\/span><span title=\"163 bronze badges\" aria-hidden=\"true\"><span class=\"badge3\"><\/span><span class=\"badgecount\">163<\/span><\/span><span class=\"v-visible-sr\">163 bronze badges<\/span>\n        <\/div>\n<\/p><\/div>\n<\/div><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p>\n<div class=\"post-layout--right js-post-comments-component\">\n<div id=\"comments-13264184\" class=\"comments js-comments-container bt bc-black-200 mt12 \" data-post-id=\"13264184\" data-min-length=\"15\">\n<ul class=\"comments-list js-comments-list\" data-remaining-comments-count=\"0\" data-canpost=\"false\" data-cansee=\"true\" data-comments-unavailable=\"false\" data-addlink-disabled=\"true\">\n<li id=\"comment-18078052\" class=\"comment js-comment \" data-comment-id=\"18078052\" data-comment-owner-id=\"468725\" data-comment-score=\"9\">\n<div class=\"js-comment-actions comment-actions\">\n<div class=\"comment-score js-comment-score js-comment-edit-hide\">\n                    <span title=\"number of 'useful comment' votes received\" class=\"warm\">9<\/span>\n            <\/div>\n<\/p><\/div>\n<div class=\"comment-text  js-comment-text-and-form\">\n<div class=\"comment-body js-comment-edit-hide\">\n<p>                <span class=\"comment-copy\">Alex, off course I do that, without it 1) and 2) wouldn&#8217;t work \ud83d\ude42<\/span><\/p>\n<div class=\"d-inline-flex ai-center\">\n\u2013\u00a0<a href=\"https:\/\/stackoverflow.com\/users\/468725\/pavel-p\" title=\"16,619 reputation\" class=\"comment-user owner\">Pavel P<\/a>\n                <\/div>\n<p>                <span class=\"comment-date\" dir=\"ltr\"><br \/>\n                    <span class=\"v-visible-sr\">Commented<\/span><br \/>\n                    <span title=\"2012-11-07 06:27:03Z, License: CC BY-SA 3.0\" class=\"relativetime-clean\">Nov 7, 2012 at 6:27<\/span><br \/>\n                <\/span>\n            <\/div>\n<\/p><\/div>\n<\/li>\n<\/ul><\/div>\n<div id=\"comments-link-13264184\" data-rep=\"50\" data-anon=\"true\">\n                    <a class=\"js-add-link comments-link disabled-link\" title=\"Use comments to ask for more information or suggest improvements. Avoid comments like \u201c+1\u201d or \u201cthanks\u201d.\" href=\"\" role=\"button\">Add a comment<\/a><br \/>\n                <span class=\"js-link-separator dno\">\u00a0|\u00a0<\/span><br \/>\n            <a class=\"js-show-link comments-link dno\" title=\"Expand to show all comments on this post\" href=\"\" onclick=\"\" role=\"button\"><\/a>\n        <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<pre><code>                    <a name=\"new-answer\"><\/a>\n\n                        <h2 class=\"bottom-notice\" data-loc=\"1\">\n                            <div><\/code><\/pre>\n<p>Not the answer you&#8217;re looking for? Browse other questions tagged <\/p>\n<ul class=\"ml0 list-ls-none js-post-tag-list-wrapper d-inline\">\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/android\" class=\"s-tag post-tag\" title=\"show questions tagged 'android'\" aria-label=\"show questions tagged 'android'\" rel=\"tag\" aria-labelledby=\"tag-android-tooltip-container\" data-tag-menu-origin=\"Unknown\">android<\/a><\/li>\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/c%2b%2b\" class=\"s-tag post-tag\" title=\"show questions tagged 'c++'\" aria-label=\"show questions tagged 'c++'\" rel=\"tag\" aria-labelledby=\"tag-c++-tooltip-container\" data-tag-menu-origin=\"Unknown\">c++<\/a><\/li>\n<li class=\"d-inline mr4 js-post-tag-list-item\"><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/java-native-interface\" class=\"s-tag post-tag\" title=\"show questions tagged 'java-native-interface'\" aria-label=\"show questions tagged 'java-native-interface'\" rel=\"tag\" aria-labelledby=\"tag-java-native-interface-tooltip-container\" data-tag-menu-origin=\"Unknown\">java-native-interface<\/a><\/li>\n<\/ul>\n<p> or <a href=\"https:\/\/stackoverflow.com\/questions\/ask\">ask your own question<\/a>.                                <\/div>\n<\/h2>\n<pre><code>            <\/div>\u6587\u7ae0\u6765\u6e90\u4e8e\u4e92\u8054\u7f51:<a href=\"https:\/\/stackoverflow.com\/questions\/13263340\/findclass-from-any-thread-in-android-jni\" target=\"_blank\" rel=\"noopener\">FindClass from any thread in Android JNI<\/a><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Android&#8217;s JNI tips page mentions this FAQ: Why di&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":71,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":0,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media\/71"}],"wp:attachment":[{"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newstrong.top\/index.php\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}