File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class Loader irritates :(

 
Padma Prasad
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Padma Prasad
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic