File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Need HELP on Class.forName()....! ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need HELP on Class.forName()....! ! " Watch "Need HELP on Class.forName()....! ! " New topic

Need HELP on Class.forName()....! !

river down

Joined: Dec 11, 2002
Posts: 21
I have a problem in Class.forName() actually it was related in Collection.sort() as well...see the code below

Collections.sort(flightList, new(<class-name>
As u can see the flightList is a vector containing my data and the 2nd argument w/c is an argument class have to derived from a variable...
How will I do it....can I used a class that forName<variable> where variable is the class name..
I code the followiwng
where variable sortType is equal to a class name "SortDATACLASS"...
But it didnt work but when u execute the following it works directly..
Collection.sort(flightList,new SortDATAClASS())
but it must not be hardcoded(class name) it must come into a variable that changes everytime....
Can someone help pls....
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
What error or exception did you get? Saying "it didn't work" does not give us much to go on.
If your sortType does not include a complete package.classname that could be the source of your problem.
Also - why did you stick this in the servlet section???
river down

Joined: Dec 11, 2002
Posts: 21
I try to include the package.....I stick to the servlet cause it was how the framework that clients used...although we argue about it....but client are demanding...anyway....i'll try...any other solutions..if it did'nt I really have to cast to a class when using Class.forName() u can see the SortClass that I used in the above codes only implements the comparator and no implementation of the compare() method....instead its implementation lies in the value of the variable (sortType...holds the name of the class)....?
Thanks very much in advance
river down

Joined: Dec 11, 2002
Posts: 21
Its working I just include the package and do some changes in the comparator class....both the CASTing class and the actual comparator class....thanks a lot
I agree. Here's the link:
subject: Need HELP on Class.forName()....! !
It's not a secret anymore!