Java Class Class problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Java Class Class problem

 
0
  #1
May 25th, 2007
Hello guys , I'll start with my code:

  1. package testapplication;
  2.  
  3. import java.util.HashMap;
  4.  
  5. public class Main {
  6.  
  7. /** Creates a new instance of Main */
  8. public Main() {
  9. }
  10.  
  11. /**
  12.   * @param args the command line arguments
  13.   */
  14. public static void main(String[] args) {
  15. // TODO code application logic here
  16. try {
  17. Class myClass = Class.forName("testapplication.MyFactory");
  18. System.out.println(myClass);
  19.  
  20. HashMap<Class,Class> daomap = new HashMap<Class,Class>();
  21.  
  22. //Interface
  23. //Real
  24. Class interfaceClass = Class.forName("testapplication.LorryDAO");
  25. daomap.put(interfaceClass, interfaceClass);
  26.  
  27. //create a new instance of the interface
  28. DAO dao;
  29. dao = (DAO)daomap.get(interfaceClass).newInstance();
  30.  
  31. LorryDAO myDao = (LorryDAO) dao;
  32. myDao.getXXXXX();
  33. } catch (Exception ex) {
  34. ex.printStackTrace();
  35. }
  36.  
  37. }
  38. }
----

  1. package testapplication;
  2.  
  3.  
  4. public class DAO {
  5.  
  6. /** Creates a new instance of DAO */
  7. public DAO() {
  8. }
  9.  
  10. public void myDAO() {}
  11. }

---

  1.  
  2. import testapplication.DAO;
  3.  
  4. public class LorryDAO extends DAO{
  5.  
  6. /** Creates a new instance of LorryDAO */
  7. public LorryDAO() {
  8. }
  9.  
  10.  
  11. public void getXXXXX() {}
  12. }

Now then lets try and explain what I'm trying to acheive here. I've got a interface which for now its the concrete class, and I'm wanting to load that into my factory or in this case main.

Its ment to get the abstract DAO and then im trying to cast it to the correct class. But once the application has ran im getting the following error.... No exception is thrown. Can anyone help me out here?

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: Java Class Class problem

 
0
  #2
May 25th, 2007
it would appear that putting System.exit(0) onto the end of main fixes the bug... is this a java bug then?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Java Class Class problem

 
0
  #3
May 26th, 2007
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2460 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC