Forums Register Login

Class.forName

+Pie Number of slices to send: Send
Hi,
Could anyone help me with this?
It is giving an error:-
Type mismatch: cannot convert from java.lang.Class to navigation.WorkerBeanImpl
public String processRequest(javax.servlet.http.HttpServletRequest request, java.sql.Connection connection) throws Exception {
WorkerBeanImpl wbImpl = null;
try {
for (int row=0; row < wbInfo.getRowCount(); row++) {
NavigationDataRow navRow = wbInfo.getRow(row);
wbImpl = Class.forName(navRow.getWorkerBean()); //ERROR
-------
-------
Thanks,
Naveen
+Pie Number of slices to send: Send
Class.forName() creates an instance of "Class" class.
To create a new instance of your object you have to call newInstance() method
+Pie Number of slices to send: Send
I tried this too:
wbImpl = Class.forName(navRow.getWorkerBean()).newInstance();
Now, it gives the following error:-
Type mismatch: cannot convert from java.lang.Object to navigation.WorkerBeanImpl
Thanks,
Naveen
+Pie Number of slices to send: Send
The newInstance method of Class returns an Object, you will need to cast this to your desired class.
wbImpl = (WorkerBeanImpl)Class.forName(navRow.getWorkerBean()).newInstance();
See:
http://www.javasoft.com/j2se/1.3/docs/api/java/lang/Class.html#newInstance()
+Pie Number of slices to send: Send
 

Originally posted by Naveen R R:
[B]Hi,
Could anyone help me with this?
It is giving an error:-
Type mismatch: cannot convert from java.lang.Class to navigation.WorkerBeanImpl
public String processRequestwbImpl = Class.forName(navRow.getWorkerBean()); //ERROR
-------
Class.forName takes a fully qualified paackage name as a String for an argument and returns the Class Object representing that name. If getWorkerBean is not doing this then you will get an error
Trevor

 
+Pie Number of slices to send: Send
Thank you very much. This works fine:
wbImpl = (WorkerBeanImpl)Class.forName(navRow.getWorkerBean()).newInstance();
Naveen
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1005 times.
Similar Threads
classnotfoundexception
Failed to load JDBC/ODBC driver.
Dynamically loading a class
Unable to Load the Driver!
what this method do in JDBC?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:15:09.