Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Class.forName = ClassNotFound (3.5 & 3.6)
Class.forName = ClassNotFound (3.5 & 3.6) [message #547576] Sun, 18 July 2010 23:01 Go to next message
Eclipse UserFriend
Originally posted by: natgross.ATgmail.com

My system is Suse Linux 11.2, Gnome, 32 bit.
Sun jvm jdk1.6.0_16.
Eclipse 3.5 or 3.6.

Class.forName ALWAYS fails. Even the following simple program.


public class TestForName {

public TestForName(String name) {
Class<?> c = test(name);
System.out.println("TestForName() Class=" + c );
}

private Class<?> test(String name) {
Class<?> c=null;
try {
c = Class.forName(name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return c;
}

public static void main(String[] args) {
//*any* class, even from same directory, even this class(!), even those from java.lang, FAIL!
new TestForName("Thread");
}
}

Please advise,
nat.
Thanks
Re: Class.forName = ClassNotFound (3.5 & 3.6) [message #547618 is a reply to message #547576] Mon, 19 July 2010 07:37 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You'll always have to use a fully qualified class name. The program you
are showing has nothing to do with OSGi and or an Eclipse plugin (you
have a main-method) so I'd suggest if you still have troubles getting
this to work to post on some Java-Beginners forum.

Tom

Am 19.07.10 01:01, schrieb nat G:
> My system is Suse Linux 11.2, Gnome, 32 bit.
> Sun jvm jdk1.6.0_16.
> Eclipse 3.5 or 3.6.
>
> Class.forName ALWAYS fails. Even the following simple program.
>
>
> public class TestForName {
>
> public TestForName(String name) {
> Class<?> c = test(name);
> System.out.println("TestForName() Class=" + c );
> }
>
> private Class<?> test(String name) {
> Class<?> c=null;
> try {
> c = Class.forName(name);
> } catch (ClassNotFoundException e) {
> e.printStackTrace();
> }
> return c;
> }
>
> public static void main(String[] args) {
> //*any* class, even from same directory, even this class(!), even those from java.lang, FAIL!
> new TestForName("Thread");
> }
> }
>
> Please advise,
> nat.
> Thanks
Re: Class.forName = ClassNotFound (3.5 & 3.6) [message #547619 is a reply to message #547576] Mon, 19 July 2010 07:36 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 19.07.2010 01:01, nat G wrote:
> My system is Suse Linux 11.2, Gnome, 32 bit.
> Sun jvm jdk1.6.0_16.
> Eclipse 3.5 or 3.6.
>
> Class.forName ALWAYS fails. Even the following simple program.
>
>
> public class TestForName {
>
> public TestForName(String name) {
> Class<?> c = test(name);
> System.out.println("TestForName() Class=" + c );
> }
>
> private Class<?> test(String name) {
> Class<?> c=null;
> try {
> c = Class.forName(name);
> } catch (ClassNotFoundException e) {
> e.printStackTrace();
> }
> return c;
> }
>
> public static void main(String[] args) {
> //*any* class, even from same directory, even this class(!), even those from java.lang, FAIL!
> new TestForName("Thread");
> }
> }
>
> Please advise,
> nat.

Please read the spec of Class#forName before attempting to
use it. The spec says:

Parameters:
className the fully qualified name of the desired class.
Returns:
the Class object for the class with the specified name.

There is no type "Thread" in the Java runtime, there exists
a type "java.lang.Thread" though.

HTH & Greetings from Bremen,

Daniel Krügler
Re: Class.forName = ClassNotFound (3.5 & 3.6) [message #547801 is a reply to message #547576] Mon, 19 July 2010 15:20 Go to previous message
Eclipse UserFriend
Originally posted by: natgross.ATgmail.com

On Sun, 18 Jul 2010 19:01:56 -0400, nat G wrote:

> My system is Suse Linux 11.2, Gnome, 32 bit. Sun jvm jdk1.6.0_16.
> Eclipse 3.5 or 3.6.
>
> Class.forName ALWAYS fails. Even the following simple program.
>
>
> public class TestForName {
>
> public TestForName(String name) {
> Class<?> c = test(name);
> System.out.println("TestForName() Class=" + c );
> }
>
> private Class<?> test(String name) {
> Class<?> c=null;
> try {
> c = Class.forName(name);
> } catch (ClassNotFoundException e) {
> e.printStackTrace();
> }
> return c;
> }
>
> public static void main(String[] args) {
> //*any* class, even from same directory, even this class(!), even
> those from java.lang, FAIL! new TestForName("Thread");
> }
> }

Thanks, Daniel & Tom. It was my obvious error.
In the past, I have had true Class.forName problems with Eclipse with jdbc,
so now, I quickly jumped the gun, blaming Eclipse. How dare I! :)
Previous Topic:Integrating C++ GUI toolkit into RCP application?
Next Topic:Eclipse HELIOS
Goto Forum:
  


Current Time: Sat Apr 20 03:36:41 GMT 2024

Powered by FUDForum. Page generated in 0.03413 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top