Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram doesn't work - NullPointerException
    primarykey
    data
    text
    <p>I am using eclipse to export my project as a runnable jar file, when I try to run it nothing happens, when I run it using cmd I get this error.</p> <pre><code>C:\Users\Enes\Desktop&gt;cmd.exe Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Enes\Desktop&gt;java -jar Game.Jar Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:58) Caused by: java.lang.NullPointerException at scrolls.Resources.createArray(Resources.java:111) at scrolls.Player.&lt;init&gt;(Player.java:31) at scrolls.Draw.&lt;init&gt;(Draw.java:27) at scrolls.Frame.main(Frame.java:18) ... 5 more C:\Users\Enes\Desktop&gt; </code></pre> <p>When I run it using eclipse it runs fine with no errors or warnings. </p> <p>This is my Resource file which seems to be causing the problem at line 111</p> <pre><code>package scrolls; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import javax.imageio.ImageIO; import org.imgscalr.Scalr; public class Resources { Map map; static BufferedImage[] textures = new BufferedImage[8]; static BufferedImage[] mapTextures = new BufferedImage[9]; static BufferedImage texture; static BufferedImage[] waterAnimated = new BufferedImage[64]; static BufferedImage water; static BufferedImage icon; public static Font f, fs; static int imageCounter = 0; public Resources() { map = new Map(); textures(); createArray(texture, textures, 32, 1, 8); createArray(water, waterAnimated, 32, 64, 1); getFont(); buildMapTextures(textures, mapTextures); } public static void counter() { imageCounter++; if (imageCounter &gt;= 500) imageCounter = 0; //System.out.println(imageCounter / 8); } private void buildMapTextures(BufferedImage[] textures, BufferedImage[] mapTextures) { for (int i = 0; i &lt;= 7; i++) { mapTextures[i] = resize(textures[i], 3, 3); } mapTextures[8] = resize(waterAnimated[2], 3, 3); } private BufferedImage resize(BufferedImage image, int newW, int newH) { BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_EXACT, newW, newH, Scalr.OP_ANTIALIAS); return thumbnail; } public static BufferedImage waterAnimation() { return waterAnimated[imageCounter / 8]; } private void textures() { try { texture = ImageIO.read(new File("src/resources/textures.png")); } catch (IOException e) { } try { water = ImageIO.read(new File("src/resources/water.png")); } catch (IOException e) { } try { icon = ImageIO.read(new File("src/resources/icon.png")); } catch (IOException e) { } } static BufferedImage player() { BufferedImage player = null; try { player = ImageIO.read(new File("src/resources/player.png")); } catch (IOException e) { } return player; } static void createArray(BufferedImage image, BufferedImage[] images, int size, int rows, int cols) { BufferedImage temp = image; for (int i = 0; i &lt; rows; i++) { for (int j = 0; j &lt; cols; j++) { images[(i * cols) + j] = temp.getSubimage(j * size, i * size, size, size); // line 111 } } } public static void readLevel(String filename, int[][] level, int part) { try { File f = new File("src/resources/levels/" + part + "/" + filename + ".txt"); FileReader fr = new FileReader(f); BufferedReader in = new BufferedReader(fr); StringBuilder sb = new StringBuilder(); byte b = 0; while ((b = (byte) in.read()) != -1) { sb.append("" + ((char) b)); } String str = sb.toString(); String[] lines = str.split("(\n|\r)+"); for (int i = 0; i &lt; lines.length; i++) { for (int j = 0; j &lt; lines[i].length(); j++) { level[i][j] = Integer.parseInt("" + lines[i].charAt(j)); } } in.close(); } catch (Exception e) { e.printStackTrace(); } } private static void getFont() { try { f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("src/resources/Jet Set.ttf")); fs = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("src/resources/Jet Set.ttf")); } catch (Exception e) { System.out.println(e); } f = f.deriveFont(22f); fs = fs.deriveFont(13f); } } </code></pre> <p>Player code</p> <pre><code>package scrolls; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Transparency; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; public class Player { static int x, y, dx, dy; BufferedImage[] sprites = new BufferedImage[8]; int rotation = 0; int imageCounter = 0; public static boolean moving = false; static int playerEnergy = 150000; static int playerLvl = 1; static int playerExp = 3; static int expNeeded = (((playerLvl + 1) * playerLvl) * 2); static int playerHealth = 100; static int playerMana = 100; static int mapRow = 6; static int mapColumn = 8; static int playerRow, playerColumn; public Player() { y = 40; x = 700; Resources.createArray(Resources.player(), sprites, 66, 1, 8); } private void changeImage() { imageCounter++; if (imageCounter &gt;= 80) imageCounter = 0; } public void move() { y = y + dy; x = x + dx; changeImage(); playerPosition(); } static void mapPosition() { if (y &lt; 0) playerRow = 0; else playerRow = (y / 32) + 1; if (x &lt; 0) playerColumn = 0; else playerColumn = (x / 32) + 1; } private void playerPosition() { if (x &gt;= 817 - 59) { x = -24; mapColumn++; } if (x &lt;= -25) { x = 817 - 59; mapColumn--; } if (y &lt;= -25) { y = 599 - 152 - 41; mapRow--; } if (y &gt;= 599 - 152 - 40) { y = -24; mapRow++; } } public static int playerExp() { return playerExp; } public static int getNextExp() { return expNeeded; } public static int playerLvl() { if (playerExp &gt;= expNeeded) { playerLvl++; } return playerLvl; } public static int playerHealth() { return playerHealth; } public static int playerMana() { return playerMana; } public static int playerEnergy() { if ((dx != 0) || (dy != 0)) playerEnergy--; if ((dx != 0) &amp;&amp; (dy != 0)) playerEnergy--; return playerEnergy; } public int getX() { return x; } public int getY() { return y; } public static BufferedImage rotate(BufferedImage image, double angle) { double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = image.getWidth(), h = image.getHeight(); int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin); GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT); Graphics2D g = result.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(angle, w / 2, h / 2); g.drawRenderedImage(image, null); g.dispose(); return result; } public BufferedImage getPlayerImage() { roatePlayer(); int image = animatePlayer(); double angle = Math.toRadians(rotation); if (dy != 0 || dx != 0) { return rotate(sprites[image], angle); } return rotate(sprites[0], angle); } private int animatePlayer() { return imageCounter / 10; } private void roatePlayer() { if (dy &gt; 0) rotation = 0; if (dy &lt; 0) rotation = 180; if (dx &gt; 0) rotation = -90; if (dx &lt; 0) rotation = 90; if (dy &gt; 0 &amp;&amp; dx &gt; 0) rotation = -45; if (dy &gt; 0 &amp;&amp; dx &lt; 0) rotation = 45; if (dy &lt; 0 &amp;&amp; dx &lt; 0) rotation = 135; if (dy &lt; 0 &amp;&amp; dx &gt; 0) rotation = -135; } public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_A) { dx = -1; rotation = -90; } if (key == KeyEvent.VK_S) { dy = 1; rotation = 0; } if (key == KeyEvent.VK_D) { dx = 1; rotation = 90; } if (key == KeyEvent.VK_W) { dy = -1; rotation = 180; } } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_A) dx = 0; if (key == KeyEvent.VK_S) dy = 0; if (key == KeyEvent.VK_D) dx = 0; if (key == KeyEvent.VK_W) dy = 0; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload