wood burning stoves 2.0*
The moose likes Java in General and the fly likes Class Loader irritates :( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class Loader irritates :(" Watch "Class Loader irritates :(" New topic
Author

Class Loader irritates :(

Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
Hi,
I am trying to load a class of my own through Class.forName() function. But this is not happening. Throwing ClassNotFoundException.
Here is my code snippet:
//package name
String s="boo.foo.hoo.";
/*
Trying to concatinate the actual class name to the package string.

The class name is a string but with spaces in between. so i split the string and store it in an array "a" and then cancatinate with the package.
*/
String [] a = classname.split(" ");
try {
for(int i=0;i<a.length;i++)
{
s = s.concat(a[i]);
}
s =s.trim();
writer.println("Class.forName("+"\""+s+"\")");
Class _rep = Class.forName("\""+s+"\"");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
and I import the package also.
import boo.foo.hoo.*;
am I doing any mistake? I cannot trace it out. It's bugging me a lot. Pease help me.
Padma.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Hi "p",
Welcome to JavaRanch!
We don't have too many rules around here, but we do have our naming policy, whichhrequires that you spell out at least your last name. Most folks around here use their full, real name -- keeps us honest! Please head over here and update yours, pronto! Thanks, parder!
Now, on to your question: Not sure what you're trying to do here:

You're putting a lot of effort into including those quote marks, but they're bollocksing up the works, for sure. If the variable s[/s] contains the name of a class, with package parts separated by dots, like [i]java.lang.Integer for instance, then you just need to write

OK?


[Jess in Action][AskingGoodQuestions]
Padma Prasad
Ranch Hand

Joined: Sep 16, 2002
Posts: 76
Thanks a ton, Ernest. I read in the API, to have quotes for the class name. Class.forName("s"); so I had hard time putting in the quotes. I removed the junk and it works.
Padma.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Hi Padma,
I'm glad to help.
Thanks for changing your display name, but I'm afraid you still haven't got it quite right: you're required to have two names, a first and last name. The first name can be an initial, but the second must be a word of two or more letters. Thanks for your cooperation!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class Loader irritates :(