8 Replies Latest reply: Dec 13, 2006 12:33 PM by 807599 RSS

    Unable to pass enum to a method

    807599
      I am trying to use a enumation to list all the graphics drivers available and when I pass it from my main class to a another objects setGraphicsDriver method (with corresponding argument) I get the error:

      init:
      deps-jar:
      Compiling 2 source files to C:\Documents and Settings\Sean\Desktop\Java Projects\EngineFramework\build\classes
      C:\Documents and Settings\Sean\Desktop\Java Projects\EngineFramework\src\engineframework\Main.java:29: setGraphicsDriver(engineframework.IrrlichtEngine.GRAPHICS_MODE) in engineframework.IrrlichtEngine cannot be applied to (engineframework.Main.GRAPHICS_MODE)
      ie.setGraphicsDriver(myobj);
      1 error
      BUILD FAILED (total time: 0 seconds)


      Here is my main class:
      package engineframework;

      public class Main {
      static enum GRAPHICS_MODE { NULL, SOFTWARE, OPENGL, DX8, DX9 }

      public static void main(String[] args) {
      IrrlichtEngine ie = new IrrlichtEngine();
      GRAPHICS_MODE myobj = GRAPHICS_MODE.OPENGL;
      ie.setGraphicsDriver(myobj);
      ie.initialiseDevice();
      }

      }

      The setGraphicsDriver method that fails:
      public void setGraphicsDriver(GRAPHICS_MODE gm) {
      System.out.println(gm); // debugging info
      // Ensure that the gm GRAPHICS_MODE is actually initialised, if not set it to OPENGL
      if(gm == null) {
      gm = GRAPHICS_MODE.OPENGL;
      }
      switch(gm) {
      case NULL:
      graphicsDriver = E_DRIVER_TYPE.EDT_NULL;
      break;
      case SOFTWARE:
      graphicsDriver = E_DRIVER_TYPE.EDT_SOFTWARE;
      break;
      case OPENGL:
      graphicsDriver = E_DRIVER_TYPE.EDT_OPENGL;
      break;
      case DX8:
      graphicsDriver = E_DRIVER_TYPE.EDT_DIRECT3D8;
      break;
      case DX9:
      graphicsDriver = E_DRIVER_TYPE.EDT_DIRECT3D9;
      break;
      default:
      graphicsDriver = E_DRIVER_TYPE.EDT_SOFTWARE;
      break;
      }
      }

      I am sure its something really silly but its driving me nuts :)
        • 1. Re: Unable to pass enum to a method
          807599
          you appear to have 2 enums called GRAPHICS_MODE, and are mixing the two up

          your switch statement can be gotten rid of, too. let your GRAPHICS_MODE enum have a method that returns the correct graphics driver, and construct each enum with it. a bit like this
           static enum GRAPHICS_MODE {
            NULL(E_DRIVER_TYPE.EDT_NULL),
           SOFTWARE(E_DRIVER_TYPE.EDT_SOFTWARE), 
            OPENGL(E_DRIVER_TYPE.EDT_OPENGL), 
            DX8(E_DRIVER_TYPE.EDT_DIRECT3D8), 
            DX9(E_DRIVER_TYPE.EDT_DIRECT3D9);
          
            private GRAPHICS_MODE(GraphicsDriver driver) {
              this.driver = driver;
            }
            private GraphicsDriver driver;
          
           public GraphicsDriver getDriver() {
              return driver;
            }
          
           } 
          obviously I've completely guessed at the actual type name of GraphicsDriver, but you get the picture
          • 2. Re: Unable to pass enum to a method
            807599
            I think I am close, this is what I now have:

            private static E_DRIVER_TYPE graphicsDriver = null;
            /// GRAPHICS_MODE - List of all available graphics modes
            private static enum GRAPHICS_MODE {
            NULL (E_DRIVER_TYPE.EDT_NULL),
            SOFTWARE (E_DRIVER_TYPE.EDT_SOFTWARE),
            SOFTWARE2 (E_DRIVER_TYPE.EDT_SOFTWARE2),
            OPENGL (E_DRIVER_TYPE.EDT_OPENGL),
            DX8 (E_DRIVER_TYPE.EDT_DIRECTX8),
            DX9 (E_DRIVER_TYPE.EDT_DIRECTX9);
            }
            // Has to return a value...?
            private GRAPHICS_MODE(E_DRIVER_TYPE edt) {
            this.graphicsDriver = edt;
            }
            public E_DRIVER_TYPE getGraphicsDriver() {
            return graphicsDriver();
            }

            Now the code return an error that I need to provide a return value (see program comment). I am not sure why I would need to do that since I looked up some more advaned enum examples and I see it being done the way that you informed me of.

            Also thanks for the assistance, too bad they don't include this tips in books :)
            • 3. Re: Unable to pass enum to a method
              807599
              any idea's anyone?
              • 4. Re: Unable to pass enum to a method
                807599
                lose the brackets at the end of return graphicsDriver()
                • 5. Re: Unable to pass enum to a method
                  807599
                  hi, really you must specify a valid return type or void if nothing is returned by this method. You only have specified the "private" modifier, but no return type.

                  Try this:
                  private void GRAPHICS_MODE(E_DRIVER_TYPE edt) {
                  this.graphicsDriver = edt;
                  }
                  Saludos!!!
                  Mario
                  • 6. Re: Unable to pass enum to a method
                    807599
                    hi, really you must specify a valid return type or
                    void if nothing is returned by this method. You only
                    have specified the "private" modifier, but no return
                    type.

                    Try this:
                    private void GRAPHICS_MODE(E_DRIVER_TYPE edt) {
                    this.graphicsDriver = edt;
                    }
                    Saludos!!!
                    Mario
                    that's a constructor

                    @OP, ignore the previous post, it's utter nonsense
                    • 7. Re: Unable to pass enum to a method
                      807599
                      a private constructor for the enum class.. i should read and learn a little bit more before come here trying to help others :/

                      will still reading and learnig :)
                      thanks and sorry for the confusion

                      Saludos!
                      Mario
                      • 8. Re: Unable to pass enum to a method
                        807599
                        I resolved the issue, had to rewrite the entire enumeration and pass it to a switch statement anyways, I was just going about it the wrong way. Thanks everyone!