Thread: Small error when i run my server

Results 1 to 9 of 9
  1. #1 Small error when i run my server 
    Registered Member dubby's Avatar
    Join Date
    Jul 2011
    Posts
    79
    Thanks given
    4
    Thanks received
    0
    Rep Power
    11
    So basically i get this small error when i run my server and i feel like its effecting my npc drops... but i have no idea what it means...




    Can someone explain to me what it means and how to fix it?
    Reply With Quote  
     

  2. #2  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    I don't even?

    Your logger is trying to log something that is null?

    Post the code blocks surrounding Logger.java line 26 and NPCDrops.java line 85, indicate each relevant line number if you could as well
    Reply With Quote  
     

  3. #3  
    Registered Member dubby's Avatar
    Join Date
    Jul 2011
    Posts
    79
    Thanks given
    4
    Thanks received
    0
    Rep Power
    11
    Logger.java:


    Code:
    package server.util.log;
    
    import java.io.PrintStream;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import server.util.SimpleTimer;
    
    /**
     * 
     * @author nick
     */
    public class Logger extends PrintStream {
    
    	private DateFormat dateFormat = new SimpleDateFormat();
    	private Date cachedDate = new Date();
    	private SimpleTimer refreshTimer = new SimpleTimer();
    
    	public Logger(PrintStream out) {
    		super(out);
    	}
    
    	@Override
    	public void print(String str) {
    		if (str.startsWith("debug:"))
    			super.print("[" + getPrefix() + "] DEBUG: " + str.substring(6));
    		else
    			super.print("[" + getPrefix() + "]: " + str);
    	}
    
    	private String getPrefix() {
    		if (refreshTimer.elapsed() > 1000) {
    			refreshTimer.reset();
    			cachedDate = new Date();
    		}
    		return dateFormat.format(cachedDate);
    	}
    }



    NPCDROPS.java:

    Code:
    package server.model.npcs;
    
    import java.io.*;
    import java.util.HashMap;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    import server.world.ItemHandler;
    import server.Server;
    import server.model.npcs.NPCHandler;
    /**
     * @author Sanity
     * @author Aintaro
     */
     
     
     /**
     * Made by Aintaro
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/npcType/npcRare.txt", true));
    BufferedWriter out2 = new BufferedWriter(new FileWriter("./Data/npcType/npcNormal.txt", true));
    try {
    out.newLine();
    out.write(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    } finally {
    //out.close();
    }
    
    out2.newLine();
    out2.write(ItemHandler.itemNames.get(npcDrops[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    *
     */
    
    public class NPCDrops {
    	
    	public NPCDrops() {
    		//loadDrops();
    	}
    	
    
    	
    	public static HashMap<Integer, int[][]> normalDrops = new HashMap<Integer, int[][]>();
    	public static HashMap<Integer, int[][]> rareDrops = new HashMap<Integer, int[][]>();
    	public static HashMap<Integer, int[]> constantDrops = new HashMap<Integer, int[]>();
    	public static HashMap<Integer, Integer> dropRarity = new HashMap<Integer,Integer>();
    	
    	
    	public static void loadDrops() {
    		try {
    			int[][][] npcDrops = new int [62585][][];
    			int[][][] rareDrops2 = new int [62585][][];
    			int[] itemRarity = new int [62585];
    			File f = new File("./Data/cfg/NPCDrops.TSM");
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/npcType/npcRare.txt", true));
    			//BufferedWriter out2 = new BufferedWriter(new FileWriter("./Data/npcType/npcNormal.txt", true));
    			Scanner s = new Scanner(f);
    			while (s.hasNextLine()) {
    				String line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer normalTok = new StringTokenizer(line, "\t");
    				line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer rareTok = new StringTokenizer(line, "\t");
    				String[] information = normalTok.nextToken().split(":");
    				int npcId = Integer.parseInt(information[0]);
    				itemRarity[npcId] = Integer.parseInt(information[1])-1;
    				npcDrops[npcId] = new int[normalTok.countTokens()][2];
    				rareDrops2[npcId] = new int[rareTok.countTokens()][2];
    				int count = 0;
    				while (normalTok.hasMoreTokens()) {
    					String[] temp = normalTok.nextToken().split(":");
    					npcDrops[npcId][count][0] = Integer.parseInt(temp[0]);
    					npcDrops[npcId][count][1] = Integer.parseInt(temp[1]);
    					//out2.newLine();
    					//out2.write(ItemHandler.itemNames.get(npcDrops[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    					count++;
    				}
    				count = 0;
    				while (rareTok.hasMoreTokens()) {
    					String[] temp = rareTok.nextToken().split(":");
    					rareDrops2[npcId][count][0] = Integer.parseInt(temp[0]);
    					//System.out.println("npc : " + NPCHandler.getSingleton().getNpcName(npcId));
    					rareDrops2[npcId][count][1] = Integer.parseInt(temp[1]);
    					//System.out.println("Raredrop: " + count + " " + rareDrops2[npcId][count][1]);
    					System.out.println(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]));
    					out.newLine();
    					out.write(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    					count ++;
    				}
    				normalDrops.put(npcId, npcDrops[npcId]);
    				rareDrops.put(npcId, rareDrops2[npcId]);
    				dropRarity.put(npcId, itemRarity[npcId]);
    			}
    			loadConstants();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}	
    	}
    	
    	public static void loadConstants() {
    		try {
    			File f = new File("./Data/cfg/NpcConstants.TSM");
    			Scanner s = new Scanner(f);
    			while (s.hasNextLine()) {
    				String line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer constantTok = new StringTokenizer(line, "\t");
    				int npcId = Integer.parseInt(constantTok.nextToken());
    				int count = 0;
    				int[] temp = new int[constantTok.countTokens()];
    				while (constantTok.hasMoreTokens()) {
    					temp[count] = Integer.parseInt(constantTok.nextToken());
    					count++;
    				}
    				constantDrops.put(npcId,temp);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	
    }
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jun 2011
    Posts
    220
    Thanks given
    3
    Thanks received
    13
    Rep Power
    2
    Can you find those lines of code and give them to let us know what the problem is? Mainly the NpcDrops and Logger
    Reply With Quote  
     

  5. #5  
    Registered Member dubby's Avatar
    Join Date
    Jul 2011
    Posts
    79
    Thanks given
    4
    Thanks received
    0
    Rep Power
    11
    Logger.java line 26:

    Code:
    		if (str.startsWith("debug:"))


    NPCDrops.java line 85:

    Code:
    System.out.println(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]));
    Reply With Quote  
     

  6. #6  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    First off, you are printing a null. This may or may not be a bad thing, I don't know the line numbers. It depends on the context or your code.

    Secondly, your print method does not ensure the argument is not null before using it as a string, this is the fix:
    Code:
    public void print(String str) {
    	if(str != null){
    		if (str.startsWith("debug:"))
    			super.print("[" + getPrefix() + "] DEBUG: " + str.substring(6));
    		else
    			super.print("[" + getPrefix() + "]: " + str);
    	}
    }
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Jun 2011
    Posts
    220
    Thanks given
    3
    Thanks received
    13
    Rep Power
    2
    Easy fix
    change it to this:
    Code:
     //System.out.println(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]));
    Why do you need it to tell you that there was a rare drop? It's pointless tbh
    Reply With Quote  
     

  8. #8  
    Registered Member dubby's Avatar
    Join Date
    Jul 2011
    Posts
    79
    Thanks given
    4
    Thanks received
    0
    Rep Power
    11
    k thanks guys idk if it was actually hurting anything on my server but im glad its gone it just looked trashy but yeah thanks!!
    Reply With Quote  
     

  9. #9  
    Banned
    Join Date
    Oct 2010
    Age
    31
    Posts
    117
    Thanks given
    2
    Thanks received
    4
    Rep Power
    0
    Also you're fixing it a way to not load drops...
    If drops arent loading, try this:
    Code:
    package server.model.npcs;
    
    import java.io.*;
    import java.util.HashMap;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    import server.world.ItemHandler;
    import server.Server;
    import server.model.npcs.NPCHandler;
    /**
     * @author Sanity
     * @author Aintaro
     */
     
     
     /**
     * Made by Aintaro
    BufferedWriter out = new BufferedWriter(new FileWriter("./Data/npcType/npcRare.txt", true));
    BufferedWriter out2 = new BufferedWriter(new FileWriter("./Data/npcType/npcNormal.txt", true));
    try {
    out.newLine();
    out.write(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    } finally {
    //out.close();
    }
    
    out2.newLine();
    out2.write(ItemHandler.itemNames.get(npcDrops[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    *
     */
    
    public class NPCDrops {
    	
    	public NPCDrops() {
    		loadDrops();
    	}
    	
    
    	
    	public static HashMap<Integer, int[][]> normalDrops = new HashMap<Integer, int[][]>();
    	public static HashMap<Integer, int[][]> rareDrops = new HashMap<Integer, int[][]>();
    	public static HashMap<Integer, int[]> constantDrops = new HashMap<Integer, int[]>();
    	public static HashMap<Integer, Integer> dropRarity = new HashMap<Integer,Integer>();
    	
    	
    	public static void loadDrops() {
    		try {
    			int[][][] npcDrops = new int [62585][][];
    			int[][][] rareDrops2 = new int [62585][][];
    			int[] itemRarity = new int [62585];
    			File f = new File("./Data/cfg/NPCDrops.TSM");
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/npcType/npcRare.txt", true));
    			//BufferedWriter out2 = new BufferedWriter(new FileWriter("./Data/npcType/npcNormal.txt", true));
    			Scanner s = new Scanner(f);
    			while (s.hasNextLine()) {
    				String line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer normalTok = new StringTokenizer(line, "\t");
    				line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer rareTok = new StringTokenizer(line, "\t");
    				String[] information = normalTok.nextToken().split(":");
    				int npcId = Integer.parseInt(information[0]);
    				itemRarity[npcId] = Integer.parseInt(information[1])-1;
    				npcDrops[npcId] = new int[normalTok.countTokens()][2];
    				rareDrops2[npcId] = new int[rareTok.countTokens()][2];
    				int count = 0;
    				while (normalTok.hasMoreTokens()) {
    					String[] temp = normalTok.nextToken().split(":");
    					npcDrops[npcId][count][0] = Integer.parseInt(temp[0]);
    					npcDrops[npcId][count][1] = Integer.parseInt(temp[1]);
    					//out2.newLine();
    					//out2.write(ItemHandler.itemNames.get(npcDrops[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    					count++;
    				}
    				count = 0;
    				while (rareTok.hasMoreTokens()) {
    					String[] temp = rareTok.nextToken().split(":");
    					rareDrops2[npcId][count][0] = Integer.parseInt(temp[0]);
    					//System.out.println("npc : " + NPCHandler.getSingleton().getNpcName(npcId));
    					rareDrops2[npcId][count][1] = Integer.parseInt(temp[1]);
    					//System.out.println("Raredrop: " + count + " " + rareDrops2[npcId][count][1]);
    					System.out.println(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]));
    					out.newLine();
    					out.write(ItemHandler.itemNames.get(rareDrops2[npcId][count][0]) + " npcName : " + NPCHandler.getSingleton().getNpcName(npcId));
    					count ++;
    				}
    				normalDrops.put(npcId, npcDrops[npcId]);
    				rareDrops.put(npcId, rareDrops2[npcId]);
    				dropRarity.put(npcId, itemRarity[npcId]);
    			}
    			loadConstants();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}	
    	}
    	
    	public static void loadConstants() {
    		try {
    			File f = new File("./Data/cfg/NpcConstants.TSM");
    			Scanner s = new Scanner(f);
    			while (s.hasNextLine()) {
    				String line = s.nextLine();
    				if (line.startsWith("#"))
    					continue;
    				StringTokenizer constantTok = new StringTokenizer(line, "\t");
    				int npcId = Integer.parseInt(constantTok.nextToken());
    				int count = 0;
    				int[] temp = new int[constantTok.countTokens()];
    				while (constantTok.hasMoreTokens()) {
    					temp[count] = Integer.parseInt(constantTok.nextToken());
    					count++;
    				}
    				constantDrops.put(npcId,temp);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	
    }
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Run server error
    By Mr Sandman in forum Help
    Replies: 0
    Last Post: 03-24-2012, 10:38 PM
  2. Server Run error
    By _Nick_ in forum Help
    Replies: 9
    Last Post: 02-07-2012, 09:44 AM
  3. Server run error? :\
    By Cheung in forum Help
    Replies: 6
    Last Post: 01-20-2012, 11:37 PM
  4. [PI] Run Server error?
    By Mikey in forum Help
    Replies: 3
    Last Post: 06-30-2011, 06:57 PM
  5. Replies: 20
    Last Post: 06-27-2011, 04:43 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •