Why am I getting class not found exception with AndroidJavaClass?











up vote
0
down vote

favorite












StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build();
StrictMode.setThreadPolicy(policy);


I tried the following code, but generates exception for class not found for ThreadPolicy



#if UNITY_ANDROID
using (AndroidJavaClass strictModeClass = new AndroidJavaClass("android.os.StrictMode"))
{
using (AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy"))
{

AndroidJavaObject Builder = threadpolicy.Call<AndroidJavaObject>("Builder");
AndroidJavaObject permitall = Builder.Call<AndroidJavaObject>("permitAll");
AndroidJavaObject build = permitall.Call<AndroidJavaObject>("build");
strictModeClass.Call<AndroidJavaObject>("setThreadPolicy", build);

}
}
#endif









share|improve this question




























    up vote
    0
    down vote

    favorite












    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
    .detectAll()
    .penaltyLog()
    .build();
    StrictMode.setThreadPolicy(policy);


    I tried the following code, but generates exception for class not found for ThreadPolicy



    #if UNITY_ANDROID
    using (AndroidJavaClass strictModeClass = new AndroidJavaClass("android.os.StrictMode"))
    {
    using (AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy"))
    {

    AndroidJavaObject Builder = threadpolicy.Call<AndroidJavaObject>("Builder");
    AndroidJavaObject permitall = Builder.Call<AndroidJavaObject>("permitAll");
    AndroidJavaObject build = permitall.Call<AndroidJavaObject>("build");
    strictModeClass.Call<AndroidJavaObject>("setThreadPolicy", build);

    }
    }
    #endif









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
      .detectAll()
      .penaltyLog()
      .build();
      StrictMode.setThreadPolicy(policy);


      I tried the following code, but generates exception for class not found for ThreadPolicy



      #if UNITY_ANDROID
      using (AndroidJavaClass strictModeClass = new AndroidJavaClass("android.os.StrictMode"))
      {
      using (AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy"))
      {

      AndroidJavaObject Builder = threadpolicy.Call<AndroidJavaObject>("Builder");
      AndroidJavaObject permitall = Builder.Call<AndroidJavaObject>("permitAll");
      AndroidJavaObject build = permitall.Call<AndroidJavaObject>("build");
      strictModeClass.Call<AndroidJavaObject>("setThreadPolicy", build);

      }
      }
      #endif









      share|improve this question















      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
      .detectAll()
      .penaltyLog()
      .build();
      StrictMode.setThreadPolicy(policy);


      I tried the following code, but generates exception for class not found for ThreadPolicy



      #if UNITY_ANDROID
      using (AndroidJavaClass strictModeClass = new AndroidJavaClass("android.os.StrictMode"))
      {
      using (AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy"))
      {

      AndroidJavaObject Builder = threadpolicy.Call<AndroidJavaObject>("Builder");
      AndroidJavaObject permitall = Builder.Call<AndroidJavaObject>("permitAll");
      AndroidJavaObject build = permitall.Call<AndroidJavaObject>("build");
      strictModeClass.Call<AndroidJavaObject>("setThreadPolicy", build);

      }
      }
      #endif






      c# unity3d android-unity-plugin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 16:55









      Programmer

      73.7k1076137




      73.7k1076137










      asked Nov 8 at 12:54









      virtplay

      120113




      120113
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.



          In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy") because ThreadPolicy is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "." in the inner class with the "$" symbol.



          Replace



          AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")


          with



          AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208180%2fwhy-am-i-getting-class-not-found-exception-with-androidjavaclass%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.



            In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy") because ThreadPolicy is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "." in the inner class with the "$" symbol.



            Replace



            AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")


            with



            AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");





            share|improve this answer

























              up vote
              0
              down vote













              It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.



              In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy") because ThreadPolicy is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "." in the inner class with the "$" symbol.



              Replace



              AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")


              with



              AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.



                In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy") because ThreadPolicy is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "." in the inner class with the "$" symbol.



                Replace



                AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")


                with



                AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");





                share|improve this answer












                It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.



                In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy") because ThreadPolicy is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "." in the inner class with the "$" symbol.



                Replace



                AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")


                with



                AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 17:21









                Programmer

                73.7k1076137




                73.7k1076137






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208180%2fwhy-am-i-getting-class-not-found-exception-with-androidjavaclass%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Landwehr

                    Reims

                    Javascript gets undefined on array