954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java Class Class problem

Hello guys , I'll start with my code:

package testapplication;

import java.util.HashMap;

public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
            Class myClass = Class.forName("testapplication.MyFactory");
            System.out.println(myClass);
            
            HashMap<Class,Class> daomap = new HashMap<Class,Class>();
            
            //Interface
            //Real
            Class interfaceClass = Class.forName("testapplication.LorryDAO");
            daomap.put(interfaceClass, interfaceClass);
            
            //create a new instance of the interface
            DAO dao;
            dao = (DAO)daomap.get(interfaceClass).newInstance();
            
            LorryDAO myDao = (LorryDAO) dao;
           myDao.getXXXXX();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
    }    
}

----

package testapplication;


public class DAO {
    
    /** Creates a new instance of DAO */
    public DAO() {
    }
    
    public void myDAO() {}
}


---

import testapplication.DAO;

public class LorryDAO extends DAO{
    
    /** Creates a new instance of LorryDAO */
    public LorryDAO() {
    }
    
    
    public void getXXXXX() {}
}


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]

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 

it would appear that putting System.exit(0) onto the end of main fixes the bug... is this a java bug then?

Acidburn
Posting Pro
511 posts since Dec 2004
Reputation Points: 12
Solved Threads: 5
 
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You