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]

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.