Class.forName = ClassNotFound (3.5 & 3.6) [message #547576] |
Sun, 18 July 2010 23:01 |
Eclipse User |
|
|
|
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 #547619 is a reply to message #547576] |
Mon, 19 July 2010 07:36 |
Daniel Krügler 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 |
Eclipse User |
|
|
|
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! :)
|
|
|
Powered by
FUDForum. Page generated in 0.03413 seconds