944,213 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3042
  • Java RSS
May 25th, 2007
0

Java Class Class problem

Expand Post »
Hello guys , I'll start with my code:

Java Syntax (Toggle Plain Text)
  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. }
----

Java Syntax (Toggle Plain Text)
  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. }

---

Java Syntax (Toggle Plain Text)
  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?

Quote ...
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]
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
May 25th, 2007
0

Re: Java Class Class problem

it would appear that putting System.exit(0) onto the end of main fixes the bug... is this a java bug then?
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
May 26th, 2007
0

Re: Java Class Class problem

Super Moderator
Featured Poster
Reputation Points: 3244
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Floating numbers
Next Thread in Java Forum Timeline: implemetation question regarding interfaces and classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC