I am trying to create a method that will instantiate a class based on a given interface. At the moment I am trying to instantiate a class based on a class name but I keep getting ClassNotFoundException
.
Can anyone tell me what I am doing wrong?
public class Message implements IExample{
@Override
public String showMessage() {
return "merge";
}
}
public static void main(String[] args) throws Exception{
Object mess = Class.forName("Message").newInstance();
}
EDIT
I have tried :
Object mess = Class.forName("com.MyExample.Message").newInstance();
Object mess = Class.forName("Project.MyExample.Message").newInstance();
Object mess = Class.forName("MyExample.Message").newInstance();
They all throw ClassNotFoundException
and a window which tells me "Source Not Found" with a button (Edit Source Lookup Path..) that let's me browse documents.
Both the main class and Message
classes are in a project called "Project" and a package called MyExample