Loading Classes by String

Put your problem here if it does not fit any of the other categories.

Loading Classes by String

Postby Bulldog » Fri Dec 05, 2008 10:14 am

Hi,

i have a problem loading classes by Strings, and i hope someone can help me.

I tried the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ClassLoader cl = ClassLoader.getSystemClassLoader();
  3.  
  4. try {
  5.  
  6.         Class c = cl.loadClass("name of the class");
  7.  
  8.         Object o = c.newInstance();
  9.  
  10. } catch (ClassNotFoundException e) {
  11.  
  12.         // TODO Auto-generated catch block
  13.  
  14.         e.printStackTrace();
  15.  
  16. }
  17.  
  18.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


But i only get the ClassNotFoundException.
Does anyone know why it dont work?

Thx,
Bulldog
Bulldog
Freshman
Freshman
 
Posts: 9
Joined: Wed Sep 24, 2008 1:54 pm

Top

Postby MrSnowflake » Fri Dec 05, 2008 12:53 pm

You must enter a fully qualified class name, and the class should be in your apk, or in the default packages provided by Adroid.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Bulldog » Fri Dec 05, 2008 2:40 pm

OK, thanks for your reply.

Could u give me an example for a fullyqualified class name is?

I tried it with "my.packet.className", but it don't work :(
Bulldog
Freshman
Freshman
 
Posts: 9
Joined: Wed Sep 24, 2008 1:54 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests