So ive been working on this RPG for awhile now but i keep getting this cursed error
DEBUG 11:02:35,740 [main] org.game.orpg.server.ServerConfig - Loaded INFO 11:02:35,741 [main] org.game.orpg.server.Server - Starting server INFO 11:02:35,779 [main] org.game.orpg.common.maps.BackgroundMapper - 84 background tiles loaded. Exception in thread "main" java.lang.NullPointerException ERROR 11:02:35,781 [main] org.game.orpg.common.maps.ArchetypeManager2 - Archetypes file not found, raising exception at org.game.orpg.common.util.StreamUtil.readLine(StreamUtil.java:13) at org.game.orpg.common.maps.ArchetypeManager2.loadFromFile(ArchetypeManager2.java:120) at org.game.orpg.common.maps.ArchetypeManager2.<init>(ArchetypeManager2.java:49) at org.game.orpg.common.maps.ArchetypeManager2.getInstance(ArchetypeManager2.java:43) at org.game.orpg.server.Server.run(Server.java:32) at org.game.orpg.server.ServerMain.main(ServerMain.java:21)
These are all the files mentioned in the error
package org.game.orpg.common.maps; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.game.orpg.common.util.PathConfig; import org.game.orpg.common.util.StreamUtil; /** * Simple, non-XML archetype manager. * * Archetypes are basically key/value pairs of strings. They also have single inheritance. * * TODO: cache full archetypes */ public class ArchetypeManager2 { private static ArchetypeManager2 instance = null; private static Logger logger = Logger.getLogger(ArchetypeManager2.class); private static final String INHERITS = "inherits"; /** * archetype_name -> {key -> value} */ private Map<String,Map<String,String>> archetypes = Collections.synchronizedMap(new HashMap<String,Map<String,String>>()); /** * List of archetype names, in the order they were loaded from file. */ private List<String> archetypeList = Collections.synchronizedList(new LinkedList<String>()); public static ArchetypeManager2 getInstance() { if (instance == null) { instance = new ArchetypeManager2(); } return instance; } public ArchetypeManager2() { loadFromFile(); } public synchronized Map<String,String> getArchetype(String name) { return archetypes.get(name); } public synchronized String getArchetypeFace(String name) { Map<String,String> props = getFullArchetype(name); if (props != null && props.containsKey("face")) { return props.get("face"); } return null; } public List<String> getArchetypeList() { return archetypeList; } /** * Get archetype with inheritance. */ public synchronized Map<String,String> getFullArchetype(String name) { Map<String,String> baseArch = getArchetype(name); if (baseArch == null) { return null; } Map<String,String> result = new HashMap<String,String>(baseArch); // now the inheritance part String parentName = name; String inherits = result.get(INHERITS); while (inherits != null) { Map<String,String> parent = getArchetype(inherits); if (parent == null) { logger.warn("Archetype '" + inherits + "' inherited by '" + parentName + "' is not defined, ignored"); break; } // Copy all non-existing keys from parent for (Map.Entry<String,String> pair : parent.entrySet()) { if (!result.containsKey(pair.getKey())) { result.put(pair.getKey(), pair.getValue()); } } parentName = inherits; inherits = parent.get(INHERITS); } result.remove(INHERITS); return result; } public synchronized void loadFromFile() { archetypeList.clear(); archetypes.clear(); String filename = PathConfig.getXmlDir() + "archetypes.txt"; BufferedReader in = null; try { in = new BufferedReader(new FileReader(filename)); } catch (FileNotFoundException e) { logger.error("Archetypes file not found, raising exception"); } String in_arch = null; Map<String,String> archMap = null; try { for (String line = StreamUtil.readLine(in); line != null; line = StreamUtil.readLine(in)) { String[] parts = line.split(" +", 2); String key = parts[0]; String value = null; if (parts.length > 1) { value = parts[1]; } if (in_arch != null) { if (line.startsWith("</")) { logger.trace("Added archetype '" + in_arch + "' with " + archMap.size() + " properties"); archetypes.put(in_arch, archMap); archetypeList.add(in_arch); in_arch = null; archMap = null; } else { archMap.put(key, value); } } else { if ("archetype".equals(key)) { in_arch = value; archMap = new HashMap<String,String>(); } else { logger.error("Unhandled line: " + line); } } } } catch (IOException e1) { logger.error("loadFromFile() failed", e1); } try { in.close(); } catch (IOException e) { logger.error("loadFromFile() close failed", e); } logger.debug(archetypes.size() + " archetypes loaded"); } public int size() { return archetypeList.size(); } public void reload() { loadFromFile(); } }package org.game.orpg.common.util; import java.io.BufferedReader; import java.io.IOException; public class StreamUtil { /** * Read a line from specially formatted file/stream. Empty/comment lines are skipped * and other lines trimmed. */ public static String readLine(BufferedReader in) throws IOException { while (true) { String line = in.readLine(); if (line == null) { return line; } line = StringUtil.trimLeft(line); if (line.length() != 0 && !line.startsWith("#")) { return line; } } } }package org.game.orpg.server; import java.net.ServerSocket; import java.net.Socket; import org.apache.log4j.Logger; import org.game.orpg.common.maps.ArchetypeManager2; import org.game.orpg.common.maps.BackgroundMapper; /** * The game server. Listens to connections from clients, and creates or loads necessary parts * of world to accommodate them. */ public class Server implements Runnable { private static Logger logger = Logger.getLogger(Server.class); private int port = ServerConfig.getInstance().getPropertyAsInt("server.port"); private ServerSocket socket; private long bytesIn = 0; private long bytesOut = 0; public Server() { } @Override public void run() { logger.info("Starting server"); BackgroundMapper.getInstance(); PlayerManager.getInstance(); ArchetypeManager2.getInstance(); logger.info("Initialization done"); // Start listening for incoming connections try { socket = new ServerSocket(port); } catch (Exception e) { logger.error("Listen failed: " + e.getMessage()); return; } WorldThread.getInstance().start(); logger.info("Listening on port " + socket.getLocalPort()); // Create a ClientThread for each while (!socket.isClosed()) { Socket client = null; try { client = socket.accept(); logger.info("New connection from " + client.getRemoteSocketAddress()); Thread ct = new Thread(new ClientThread(client, this)); ct.setName("ClientThread"); ct.start(); } catch (Exception e) { logger.error("Accept failed", e); } } } public int getPort() { return port; } public void setPort(int port) { this.port = port; } public synchronized void incrementBytesTransferred(long in, long out) { bytesIn += in; bytesOut += out; } public long getBytesIn() { return bytesIn; } public long getBytesOut() { return bytesOut; } }package org.game.orpg.server; public class ServerMain { public static void main(String[] args) { System.setProperty("log4j.configuration", "log4j-server.properties"); Server server = new Server(); for (int i = 0; i < args.length; i++) { if ("--help".equals(args[i]) || "-h".equals(args[i])) { System.out.println("Options:\n-p <port>\tListen on <port>\n\n"); System.exit(1); } else if ("--port".equals(args[i]) || "-p".equals(args[i])) { server.setPort(Integer.parseInt(args[i+1])); i++; } } server.run(); } }
If its any help I am pretty sure the error is in ArchetypeManager2