ClassNotFoundException with Class.forName(“int”)
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
add a comment |
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
Tryjava.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
add a comment |
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
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
java
asked Jan 1 at 18:20
vanhemtvanhemt
647
647
Tryjava.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
add a comment |
Tryjava.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
add a comment |
5 Answers
5
active
oldest
votes
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 methodClass.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
but still i'm not able to access at usingClass.forName()
– Deadpool
Jan 1 at 19:57
@Deadpool That's right, you can't useClass.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 useClass.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 thatint
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
|
show 1 more comment
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)
add a comment |
Class.forName
is for class objects but int
is primitive data type.
Try java.lang.Integer
instead.
add a comment |
int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 methodClass.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
but still i'm not able to access at usingClass.forName()
– Deadpool
Jan 1 at 19:57
@Deadpool That's right, you can't useClass.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 useClass.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 thatint
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
|
show 1 more comment
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 methodClass.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
but still i'm not able to access at usingClass.forName()
– Deadpool
Jan 1 at 19:57
@Deadpool That's right, you can't useClass.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 useClass.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 thatint
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
|
show 1 more comment
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 methodClass.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
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 methodClass.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
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 usingClass.forName()
– Deadpool
Jan 1 at 19:57
@Deadpool That's right, you can't useClass.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 useClass.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 thatint
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
|
show 1 more comment
but still i'm not able to access at usingClass.forName()
– Deadpool
Jan 1 at 19:57
@Deadpool That's right, you can't useClass.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 useClass.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 thatint
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
|
show 1 more comment
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)
add a comment |
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)
add a comment |
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)
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)
answered Jan 1 at 18:23
johnheroyjohnheroy
32615
32615
add a comment |
add a comment |
Class.forName
is for class objects but int
is primitive data type.
Try java.lang.Integer
instead.
add a comment |
Class.forName
is for class objects but int
is primitive data type.
Try java.lang.Integer
instead.
add a comment |
Class.forName
is for class objects but int
is primitive data type.
Try java.lang.Integer
instead.
Class.forName
is for class objects but int
is primitive data type.
Try java.lang.Integer
instead.
answered Jan 1 at 21:30


AlonAlon
608129
608129
add a comment |
add a comment |
int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".
add a comment |
int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".
add a comment |
int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".
int is a primitive data type, not a class. Integer class can be used for int. So you should use "Integer".
answered Jan 1 at 18:25


mahfuj asifmahfuj asif
31617
31617
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 1 at 18:26
Pankaj SinghalPankaj Singhal
6,54452344
6,54452344
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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