Cant make work a pattern

Hi guys i have this pice of code that does not working ,and its only on jmonkey soo i wanted to ask if any 1 know anything about it
now here is a huge pice of code and that part that does not work is betwin huge ////

[java]

 public String myStringa3D;

public void setStringa3D(String Stringa3D) {
    this.myStringa3D = Stringa3D;
}
 
 //2Dinterface
interface A2DInterface{
   public void execute();
}
/
class Test implements A2DInterface{
           public void execute(){
               myStringa3D = "next class";
           }
       }



/** Defining the "Shoot" action: Determine what was hit and how to respond. */
    private ActionListener actionListener = new ActionListener() {

public void onAction(String name, boolean keyPressed, float tpf) {
  if (name.equals("Shoot") && !keyPressed) {
      
     
      //My Click Start
       
      
      
      if(inputManager.getCursorPosition().getX()<(settings.getWidth()/100*5)){
         
              
              try {
                  //2D ray
                  Vector3f myVector2D = new Vector3f(inputManager.getCursorPosition().getX(),
               inputManager.getCursorPosition().getY(),0);
                  Vector3f myVector2Df = new Vector3f(0,0,1);
                  Ray myRay = new Ray(myVector2D, myVector2Df);
                    CollisionResults myResults = new CollisionResults();
                        guiNode.collideWith(myRay, myResults);
                      
                        
       MyGeometry gk=(MyGeometry) myResults.getClosestCollision().getGeometry();
            //////////////////////////////////////////////////////////
          ///////////////////////////////////////////////////
         //////////////////////////////////////////////////////////
         //////////////////////////////////////////////////////////
        Class<?> MyClass = Class.forName(gk.getClassName());
         
       A2DInterface firstStep = ((Class<A2DInterface>)MyClass).newInstance();
            
       firstStep.execute();
        //////////////////////////////////////////////////////////
       //////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////
     
                  
      System.out.println("2D try WORKED OUT  "+myStringa3D);
              } catch (Exception e) {
                  System.out.println("2D try Collapsed");
              }
              
        //System.out.println("Crashed?");
     
          System.out.println("fine 2D");
      }
      else{

}

[/java]
//may be missing some } below

1 Like
 //
      Class<?> MyClass = Class.forName(gk.getClassName());

   A2DInterface firstStep = ((Class<A2DInterface>)MyClass).newInstance();

   firstStep.execute();

     //

this is the pice that is not working

1 Like

Well, you didn’t post the important parts of the code… or what “not working” means.

My guess, you are getting an exception when you instantiate the object because it is an inner class and you can’t instantiate inner classes that way unless they are static.

But I don’t have enough information to know if it’s really an inner class… or what the exception is.

1 Like

Code stops working here

Class<?> MyClass = Class.forName(gk.getClassName());
and i dont know what exactly goes wrong
i tried use other clases ,just to test but still…

1 Like

As in:

  1. game exits?
  2. computer crashes?
  3. house explodes in a giant fireball?
  4. exception is thrown?

This is not a JME problem. It’s a general Java problem.

3 Likes

:smiley: house explodes :smiley: i have puted it in catch as u see in code :slight_smile: and after each line in catch i used system print out
soo i see each line ,well after that line
Class<?> MyClass = Class.forName(gk.getClassName());
it do not write any thing ,and goes to catch
and print the catch system print out
But it might be the inner classproblem,i’ve tried it static but gave no difference… eehh i will keep try

1 Like

But you chose not to provide it? You have an exception. It will tell you EVERYTHING you need to know… if you simply print it out with the stack trace.

e.printStackTrace();

Good luck with your game.

1 Like

2D try WORKED OUT TILL HERE 3 NewClass
java.lang.ClassNotFoundException: NewClass
2D try Collapsed
fine 2D
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at MyCityBuilder.ClickingTry$2.onAction(ClickingTry.java:179)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:433)
at com.jme3.input.InputManager.processQueue(InputManager.java:833)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

changed a pice of code now its not Test but NewClass and now i know its not inner class problem

1 Like

Damn …what can i say… i mesed it up …
thnx for advice on e.printStackTrace();
i was now giving the full path on the name of the class…ehhh what can i say :smiley:
any way thnx for help men.
solved

1 Like