Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

reflection newInstance

Thread view: 
Mike Phelps - 20 Sep 2005 23:19 GMT
Hi Guys,

Object obj = Class.forName("java.lang.Integer").newInstance(); throws
a java.lang.InstantiationException. why? what does it mean? How can I
build an Integer with a default value when all I have is a string:
"java.lang.Integer". It is from an xml file that contains type of an
object, It could also be java.lang.Float or java.lang.Double.

Thanks.
Oliver Wong - 20 Sep 2005 23:20 GMT
> Object obj = Class.forName("java.lang.Integer").newInstance(); throws
> a java.lang.InstantiationException. why? what does it mean?

What does it say on
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InstantiationException.html ?

> How can I
> build an Integer with a default value when all I have is a string:
> "java.lang.Integer".

   You cannot. The Integer class
(http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html) doesn't
have a "default" value. You have to specify a value.

> It is from an xml file that contains type of an
> object, It could also be java.lang.Float or java.lang.Double.

See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Float.html and
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html

   - Oliver
Roedy Green - 21 Sep 2005 00:39 GMT
>Object obj = Class.forName("java.lang.Integer").newInstance(); throws
>a java.lang.InstantiationException. why? what does it mean? How can I
>build an Integer with a default value when all I have is a string:
>"java.lang.Integer". It is from an xml file that contains type of an
>object, It could also be java.lang.Float or java.lang.Double.

Integer has no default constructor.  Since it is immutable, an Integer
(0) created that way would not be a very useful beast.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.