ClassNotFoundException with Class.forName(“int”)












-2















Please note that I can't get forName() to work specifically with "int".
On the other hand, it works alright with a class I created in the same package as



Class.forName("mypackage.dummyclass")


Is that something to do with fully qualified names? I've tried "java.lang.int" and "java.lang.integer", but it didn't help.










share|improve this question























  • Try java.lang.Integer, with an upper-case I.

    – Joe C
    Jan 1 at 18:21






  • 1





    I would strongly advice not to do so. What makes you do that?

    – Dorian Gray
    Jan 1 at 18:23











  • Class.forName is for class objects, int is primitive data type, Integer is wrapper class

    – Deadpool
    Jan 1 at 18:23











  • @DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

    – vanhemt
    Jan 2 at 1:57
















-2















Please note that I can't get forName() to work specifically with "int".
On the other hand, it works alright with a class I created in the same package as



Class.forName("mypackage.dummyclass")


Is that something to do with fully qualified names? I've tried "java.lang.int" and "java.lang.integer", but it didn't help.










share|improve this question























  • Try java.lang.Integer, with an upper-case I.

    – Joe C
    Jan 1 at 18:21






  • 1





    I would strongly advice not to do so. What makes you do that?

    – Dorian Gray
    Jan 1 at 18:23











  • Class.forName is for class objects, int is primitive data type, Integer is wrapper class

    – Deadpool
    Jan 1 at 18:23











  • @DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

    – vanhemt
    Jan 2 at 1:57














-2












-2








-2








Please note that I can't get forName() to work specifically with "int".
On the other hand, it works alright with a class I created in the same package as



Class.forName("mypackage.dummyclass")


Is that something to do with fully qualified names? I've tried "java.lang.int" and "java.lang.integer", but it didn't help.










share|improve this question














Please note that I can't get forName() to work specifically with "int".
On the other hand, it works alright with a class I created in the same package as



Class.forName("mypackage.dummyclass")


Is that something to do with fully qualified names? I've tried "java.lang.int" and "java.lang.integer", but it didn't help.







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 18:20









vanhemtvanhemt

647




647













  • Try java.lang.Integer, with an upper-case I.

    – Joe C
    Jan 1 at 18:21






  • 1





    I would strongly advice not to do so. What makes you do that?

    – Dorian Gray
    Jan 1 at 18:23











  • Class.forName is for class objects, int is primitive data type, Integer is wrapper class

    – Deadpool
    Jan 1 at 18:23











  • @DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

    – vanhemt
    Jan 2 at 1:57



















  • Try java.lang.Integer, with an upper-case I.

    – Joe C
    Jan 1 at 18:21






  • 1





    I would strongly advice not to do so. What makes you do that?

    – Dorian Gray
    Jan 1 at 18:23











  • Class.forName is for class objects, int is primitive data type, Integer is wrapper class

    – Deadpool
    Jan 1 at 18:23











  • @DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

    – vanhemt
    Jan 2 at 1:57

















Try java.lang.Integer, with an upper-case I.

– Joe C
Jan 1 at 18:21





Try java.lang.Integer, with an upper-case I.

– Joe C
Jan 1 at 18:21




1




1





I would strongly advice not to do so. What makes you do that?

– Dorian Gray
Jan 1 at 18:23





I would strongly advice not to do so. What makes you do that?

– Dorian Gray
Jan 1 at 18:23













Class.forName is for class objects, int is primitive data type, Integer is wrapper class

– Deadpool
Jan 1 at 18:23





Class.forName is for class objects, int is primitive data type, Integer is wrapper class

– Deadpool
Jan 1 at 18:23













@DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

– vanhemt
Jan 2 at 1:57





@DorianGray Just got confused working through somebody else's example that generates classes on the fly. Will change to int.class now that I'm clear as to what's going on.

– vanhemt
Jan 2 at 1:57












5 Answers
5






active

oldest

votes


















2














The correct syntax for getting the Class object associated with primitive types, like int, is



int.class


Likewise, you use byte.class, long.class, boolean.class, etc. for the other primitive types.



While there's a special relationship between int and java.lang.Integer, int.class is not the same thing as Integer.class.



Note that you cannot use Class.forName with a primitive type name.



As documented in the Java tutorial:




Class.forName()

If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). This cannot be used for primitive types.




And from the same tutorial, on how to use the .class syntax with primitives:




The .class Syntax

If the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. This is also the easiest way to obtain the Class for a primitive type.



boolean b;
Class c = b.getClass(); // compile-time error
Class c = boolean.class; // correct







share|improve this answer


























  • but still i'm not able to access at using Class.forName()

    – Deadpool
    Jan 1 at 19:57











  • @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

    – ernest_k
    Jan 1 at 20:00













  • Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

    – Deadpool
    Jan 1 at 20:07






  • 1





    That's perfect, thanks for links

    – Deadpool
    Jan 1 at 20:19






  • 1





    @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

    – vanhemt
    Jan 2 at 1:54



















3














int is a primitive type in Java, not a class, so try java.lang.Integer instead (which is not exactly the same thing but is interchangeable for many purposes)






share|improve this answer































    1














    Class.forName is for class objects but int is primitive data type.



    Try java.lang.Integer instead.






    share|improve this answer































      0














      int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".






      share|improve this answer































        0














        Instead of java.lang.integer, try java.lang.Integer (With Capital I)





        The above will work because, Class.forName() tries to create an object of the full class name passed as String arg in it.



        java.lang.Integer - This is a class



        int - This is not a class. It is a primitive data type. Hence, failing.






        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',
          autoActivateHeartbeat: false,
          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%2f53997837%2fclassnotfoundexception-with-class-fornameint%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The correct syntax for getting the Class object associated with primitive types, like int, is



          int.class


          Likewise, you use byte.class, long.class, boolean.class, etc. for the other primitive types.



          While there's a special relationship between int and java.lang.Integer, int.class is not the same thing as Integer.class.



          Note that you cannot use Class.forName with a primitive type name.



          As documented in the Java tutorial:




          Class.forName()

          If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). This cannot be used for primitive types.




          And from the same tutorial, on how to use the .class syntax with primitives:




          The .class Syntax

          If the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. This is also the easiest way to obtain the Class for a primitive type.



          boolean b;
          Class c = b.getClass(); // compile-time error
          Class c = boolean.class; // correct







          share|improve this answer


























          • but still i'm not able to access at using Class.forName()

            – Deadpool
            Jan 1 at 19:57











          • @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

            – ernest_k
            Jan 1 at 20:00













          • Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

            – Deadpool
            Jan 1 at 20:07






          • 1





            That's perfect, thanks for links

            – Deadpool
            Jan 1 at 20:19






          • 1





            @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

            – vanhemt
            Jan 2 at 1:54
















          2














          The correct syntax for getting the Class object associated with primitive types, like int, is



          int.class


          Likewise, you use byte.class, long.class, boolean.class, etc. for the other primitive types.



          While there's a special relationship between int and java.lang.Integer, int.class is not the same thing as Integer.class.



          Note that you cannot use Class.forName with a primitive type name.



          As documented in the Java tutorial:




          Class.forName()

          If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). This cannot be used for primitive types.




          And from the same tutorial, on how to use the .class syntax with primitives:




          The .class Syntax

          If the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. This is also the easiest way to obtain the Class for a primitive type.



          boolean b;
          Class c = b.getClass(); // compile-time error
          Class c = boolean.class; // correct







          share|improve this answer


























          • but still i'm not able to access at using Class.forName()

            – Deadpool
            Jan 1 at 19:57











          • @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

            – ernest_k
            Jan 1 at 20:00













          • Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

            – Deadpool
            Jan 1 at 20:07






          • 1





            That's perfect, thanks for links

            – Deadpool
            Jan 1 at 20:19






          • 1





            @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

            – vanhemt
            Jan 2 at 1:54














          2












          2








          2







          The correct syntax for getting the Class object associated with primitive types, like int, is



          int.class


          Likewise, you use byte.class, long.class, boolean.class, etc. for the other primitive types.



          While there's a special relationship between int and java.lang.Integer, int.class is not the same thing as Integer.class.



          Note that you cannot use Class.forName with a primitive type name.



          As documented in the Java tutorial:




          Class.forName()

          If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). This cannot be used for primitive types.




          And from the same tutorial, on how to use the .class syntax with primitives:




          The .class Syntax

          If the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. This is also the easiest way to obtain the Class for a primitive type.



          boolean b;
          Class c = b.getClass(); // compile-time error
          Class c = boolean.class; // correct







          share|improve this answer















          The correct syntax for getting the Class object associated with primitive types, like int, is



          int.class


          Likewise, you use byte.class, long.class, boolean.class, etc. for the other primitive types.



          While there's a special relationship between int and java.lang.Integer, int.class is not the same thing as Integer.class.



          Note that you cannot use Class.forName with a primitive type name.



          As documented in the Java tutorial:




          Class.forName()

          If the fully-qualified name of a class is available, it is possible to get the corresponding Class using the static method Class.forName(). This cannot be used for primitive types.




          And from the same tutorial, on how to use the .class syntax with primitives:




          The .class Syntax

          If the type is available but there is no instance then it is possible to obtain a Class by appending ".class" to the name of the type. This is also the easiest way to obtain the Class for a primitive type.



          boolean b;
          Class c = b.getClass(); // compile-time error
          Class c = boolean.class; // correct








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 20:16

























          answered Jan 1 at 18:59









          ernest_kernest_k

          23.5k42749




          23.5k42749













          • but still i'm not able to access at using Class.forName()

            – Deadpool
            Jan 1 at 19:57











          • @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

            – ernest_k
            Jan 1 at 20:00













          • Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

            – Deadpool
            Jan 1 at 20:07






          • 1





            That's perfect, thanks for links

            – Deadpool
            Jan 1 at 20:19






          • 1





            @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

            – vanhemt
            Jan 2 at 1:54



















          • but still i'm not able to access at using Class.forName()

            – Deadpool
            Jan 1 at 19:57











          • @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

            – ernest_k
            Jan 1 at 20:00













          • Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

            – Deadpool
            Jan 1 at 20:07






          • 1





            That's perfect, thanks for links

            – Deadpool
            Jan 1 at 20:19






          • 1





            @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

            – vanhemt
            Jan 2 at 1:54

















          but still i'm not able to access at using Class.forName()

          – Deadpool
          Jan 1 at 19:57





          but still i'm not able to access at using Class.forName()

          – Deadpool
          Jan 1 at 19:57













          @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

          – ernest_k
          Jan 1 at 20:00







          @Deadpool That's right, you can't use Class.forName("int") for that, that's why Java gave a special syntax for that. int.class is what you're looking for, why do you want to use Class.forname? Are you loading classes from dynamic names/strings?

          – ernest_k
          Jan 1 at 20:00















          Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

          – Deadpool
          Jan 1 at 20:07





          Class.forName() must work for all the classes and interfaces, so curious that int has class and it is not working for that, i'm curious to know why? either those classes are written in some other Native languages ?

          – Deadpool
          Jan 1 at 20:07




          1




          1





          That's perfect, thanks for links

          – Deadpool
          Jan 1 at 20:19





          That's perfect, thanks for links

          – Deadpool
          Jan 1 at 20:19




          1




          1





          @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

          – vanhemt
          Jan 2 at 1:54





          @ernest_k I just thought, since I can do int.class, that same class could be accessed through forName. Hence the confusion.

          – vanhemt
          Jan 2 at 1:54













          3














          int is a primitive type in Java, not a class, so try java.lang.Integer instead (which is not exactly the same thing but is interchangeable for many purposes)






          share|improve this answer




























            3














            int is a primitive type in Java, not a class, so try java.lang.Integer instead (which is not exactly the same thing but is interchangeable for many purposes)






            share|improve this answer


























              3












              3








              3







              int is a primitive type in Java, not a class, so try java.lang.Integer instead (which is not exactly the same thing but is interchangeable for many purposes)






              share|improve this answer













              int is a primitive type in Java, not a class, so try java.lang.Integer instead (which is not exactly the same thing but is interchangeable for many purposes)







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 1 at 18:23









              johnheroyjohnheroy

              32615




              32615























                  1














                  Class.forName is for class objects but int is primitive data type.



                  Try java.lang.Integer instead.






                  share|improve this answer




























                    1














                    Class.forName is for class objects but int is primitive data type.



                    Try java.lang.Integer instead.






                    share|improve this answer


























                      1












                      1








                      1







                      Class.forName is for class objects but int is primitive data type.



                      Try java.lang.Integer instead.






                      share|improve this answer













                      Class.forName is for class objects but int is primitive data type.



                      Try java.lang.Integer instead.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 1 at 21:30









                      AlonAlon

                      608129




                      608129























                          0














                          int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".






                          share|improve this answer




























                            0














                            int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".






                            share|improve this answer


























                              0












                              0








                              0







                              int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".






                              share|improve this answer













                              int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 1 at 18:25









                              mahfuj asifmahfuj asif

                              31617




                              31617























                                  0














                                  Instead of java.lang.integer, try java.lang.Integer (With Capital I)





                                  The above will work because, Class.forName() tries to create an object of the full class name passed as String arg in it.



                                  java.lang.Integer - This is a class



                                  int - This is not a class. It is a primitive data type. Hence, failing.






                                  share|improve this answer




























                                    0














                                    Instead of java.lang.integer, try java.lang.Integer (With Capital I)





                                    The above will work because, Class.forName() tries to create an object of the full class name passed as String arg in it.



                                    java.lang.Integer - This is a class



                                    int - This is not a class. It is a primitive data type. Hence, failing.






                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Instead of java.lang.integer, try java.lang.Integer (With Capital I)





                                      The above will work because, Class.forName() tries to create an object of the full class name passed as String arg in it.



                                      java.lang.Integer - This is a class



                                      int - This is not a class. It is a primitive data type. Hence, failing.






                                      share|improve this answer













                                      Instead of java.lang.integer, try java.lang.Integer (With Capital I)





                                      The above will work because, Class.forName() tries to create an object of the full class name passed as String arg in it.



                                      java.lang.Integer - This is a class



                                      int - This is not a class. It is a primitive data type. Hence, failing.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 1 at 18:26









                                      Pankaj SinghalPankaj Singhal

                                      6,54452344




                                      6,54452344






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997837%2fclassnotfoundexception-with-class-fornameint%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

                                          MongoDB - Not Authorized To Execute Command

                                          How to fix TextFormField cause rebuild widget in Flutter

                                          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith