how to Create a Java Package from MATLAB Code?

Anyone know why I'm getting an error with this code ? I'm stumped thanks:D?

  • package MainPackage; import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BI… import static org.lwjgl.opengl.GL11.GL_MODELVIEW; import static org.lwjgl.opengl.GL11.GL_PROJECTION; import static org.lwjgl.opengl.GL11.GL_QUADS; import static org.lwjgl.opengl.GL11.glBegin; import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glEnd; import static org.lwjgl.opengl.GL11.glLoadIdentity; import static org.lwjgl.opengl.GL11.glMatrixMode; import static org.lwjgl.opengl.GL11.glOrtho; import static org.lwjgl.opengl.GL11.glVertex2i; import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; ; public class Main { public static enum State{ INTRO, MAIN_MENU, GAME; } public State state = State.INTRO; public Main() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setTitle("Maths"); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); } // Initialization code OpenGL glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glMatrixMode(GL_MODELVIEW); /*MAIN STUFF*/ while (!Display.isCloseRequested()) { // Render glClear(GL_COLOR_BUFFER_BIT); if(Menu.isInBounds = true && Mouse.isButtonDown(0)){ Display.destroy(); System.exit(0); } Menu.draw(); if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)… { Display.destroy(); System.exit(0); } int mousex = Mouse.getX(); int mousey = 480 - Mouse.getY(); //TESTING JUST PRINTS X & Y if(Mouse.isButtonDown(0) ) System.out.println("X : " + mousex + "|| Y :" + mousey); Display.update(); Display.sync(60); } // auto destroy if error across Display.destroy(); } /* end of constructor */ public static void main(String[] args) { new Main(); Menu.draw(); } } // Menu Class package MainPackage; import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BI… import static org.lwjgl.opengl.GL11.GL_MODELVIEW; import static org.lwjgl.opengl.GL11.GL_PROJECTION; import static org.lwjgl.opengl.GL11.GL_QUADS; import static org.lwjgl.opengl.GL11.glBegin; import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glEnd; import static org.lwjgl.opengl.GL11.glLoadIdentity; import static org.lwjgl.opengl.GL11.glMatrixMode; import static org.lwjgl.opengl.GL11.glOrtho; import static org.lwjgl.opengl.GL11.glVertex2i; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.Display; public class Menu { public Menu(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 1, -1); glMatrixMode(GL_MODELVIEW); } public static int x1; public static int x2; public static int y1; public static int y2; static void draw(){ x1 = 170; x2 = 470; y1 = 200; y2 = 250; glBegin(GL_QUADS); glVertex2i(x1, y1); // Upper-left glVertex2i(x2, y1); // Upper-right glVertex2i(x2, y2); // Bottom-right glVertex2i(x1, y2); // Bottom-left glEnd(); } static boolean isInBounds; boolean isInBounds(int mousex, int mousey){ if(mousex > x1 && mousex < x2 && mousey > y1 && mousey < y2){ return true; } else{ return false; } } } // it runs fine but the x & y wont print out and when i close it a get the following error Exception in thread "main" java.lang.NullPointerException at org.lwjgl.opengl.GL11.glBegin(GL11.java:… at MainPackage.Menu.draw(Menu.java:40) at MainPackage.Main.main(Main.java:86)

  • Answer:

    According to what it says, check line 86 in Main.java. However without full use of all import statements, we cannot see what you are trying to do.

Josh at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.