Thread: Need help with Java error

Results 1 to 6 of 6
  1. #1 Need help with Java error 
    Registered Member
    Join Date
    Jul 2017
    Posts
    25
    Thanks given
    16
    Thanks received
    1
    Rep Power
    10
    I have never experienced this error and it's causing all of my items to no longer have requirements, stats, etc. I am hoping it's something simple.


    My Error:

    Code:
    Sep 07, 2018 3:05:12 AM com.arlania.GameServer main
    INFO: Initializing the loader...
    Exception in thread "GameLoadingThread" java.lang.NullPointerException
    	at com.arlania.model.definitions.ItemDefinition.init(ItemDefinition.java:75)
    	at com.arlania.GameLoader.lambda$5(GameLoader.java:129)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)

    Below is itemDefinition.java
    The line that is red and larger text is the line with the error.

    Code:
    package com.arlania.model.definitions;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    
    import com.arlania.model.container.impl.Equipment;
    
    /**
     * This file manages every item definition, which includes
     * their name, description, value, skill requirements, etc.
     * 
     * @author relex lawl
     */
    
    public class ItemDefinition {
    	
    	/**
    	 * The directory in which item definitions are found.
    	 */
    	private static final String FILE_DIRECTORY = "./data/def/txt/items.txt";
    
    	/**
    	 * The max amount of items that will be loaded.
    	 */
    	private static final int MAX_AMOUNT_OF_ITEMS = 22694;
    	
    	/**
    	 * ItemDefinition array containing all items' definition values.
    	 */
    	private static ItemDefinition[] definitions = new ItemDefinition[MAX_AMOUNT_OF_ITEMS];
    	
    	/**
    	 * Loading all item definitions
    	 */
    	public static void init() {
    		ItemDefinition definition = definitions[0];
    		try {
    			File file = new File(FILE_DIRECTORY);
    			BufferedReader reader = new BufferedReader(new FileReader(file));
    			String line;
    			while ((line = reader.readLine()) != null) {
    				if (line.contains("inish")) {
    					definitions[definition.id] = definition;
    					continue;
    				}
    				String[] args = line.split(": ");
    				if (args.length <= 1)
    					continue;
    				String token = args[0], value = args[1];
    				if (line.contains("Bonus[")) {
    					String[] other = line.split("]");
    					int index = Integer.valueOf(line.substring(6, other[0].length()));
    					double bonus = Double.valueOf(value);
    					definition.bonus[index] = bonus;
    					continue;
    				}
    				if (line.contains("Requirement[")) {
    					String[] other = line.split("]");
    					int index = Integer.valueOf(line.substring(12, other[0].length()));
    					int requirement = Integer.valueOf(value);
    					definition.requirement[index] = requirement;
    					continue;
    				}
    				switch (token.toLowerCase()) {
    				case "item id":
    					int id = Integer.valueOf(value);
    					definition = new ItemDefinition();
    					definition.id = id;
    					break;
    				case "name":
    					if(value == null)
    						continue;
    					definition.name = value;
    					break;
    				case "examine":
    					definition.description = value;
    					break;
    				case "value":
    					int price = Integer.valueOf(value);
    					definition.value = price;
    					break;
    				case "stackable":
    					definition.stackable = Boolean.valueOf(value);
    					break;
    				case "noted":
    					definition.noted = Boolean.valueOf(value);
    					break;
    				case "double-handed":
    					definition.isTwoHanded = Boolean.valueOf(value);
    					break;
    				case "equipment type":
    					definition.equipmentType = EquipmentType.valueOf(value);
    					break;
    				case "is weapon":
    					definition.weapon = Boolean.valueOf(value);
    					break;
    				}
    			}
    			reader.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}	
    	
    	public static ItemDefinition[] getDefinitions() {
    		return definitions;
    	}
    	
    	/**
    	 * Gets the item definition correspondent to the id.
    	 * 
    	 * @param id	The id of the item to fetch definition for.
    	 * @return		definitions[id].
    	 */
    	public static ItemDefinition forId(int id) {
    		return (id < 0 || id > definitions.length || definitions[id] == null) ? new ItemDefinition() : definitions[id];
    	}
    	
    	/**
    	 * Gets the max amount of items that will be loaded
    	 * in Niobe.
    	 * @return	The maximum amount of item definitions loaded.
    	 */
    	public static int getMaxAmountOfItems() {
    		return MAX_AMOUNT_OF_ITEMS;
    	}
    	
    	/**
    	 * The id of the item.
    	 */
    	private int id = 0;
    	
    	/**
    	 * Gets the item's id.
    	 * 
    	 * @return id.
    	 */
    	public int getId() {
    		return id;
    	}
    	
    	/**
    	 * The name of the item.
    	 */
    	private String name = "None";
    	
    	/**
    	 * Gets the item's name.
    	 * 
    	 * @return name.
    	 */
    	public String getName() {
    		return name;
    	}
    	
    	/**
    	 * The item's description.
    	 */
    	private String description = "Null";
    	
    	/**
    	 * Gets the item's description.
    	 * 
    	 * @return	description.
    	 */
    	public String getDescription() {
    		return description;
    	}
    	
    	/**
    	 * Flag to check if item is stackable.
    	 */
    	private boolean stackable;
    	
    	/**
    	 * Checks if the item is stackable.
    	 * 
    	 * @return	stackable.
    	 */
    	public boolean isStackable() {
    		if(noted)
    			return true;
    		return stackable;
    	}
    	
    	/**
    	 * The item's shop value.
    	 */
    	private int value;
    	
    	/**
    	 * Gets the item's shop value.
    	 * 
    	 * @return	value.
    	 */
    	public int getValue() {
    		return isNoted() ? ItemDefinition.forId(getId() - 1).value : value;
    	}
    	
    	/**
    	 * Gets the item's equipment slot index.
    	 * 
    	 * @return	equipmentSlot.
    	 */
    	public int getEquipmentSlot() {
    		return equipmentType.slot;
    	}
    	
    	/**
    	 * Flag that checks if item is noted.
    	 */
    	private boolean noted;
    	
    	/**
    	 * Checks if item is noted.
    	 * 
    	 * @return noted.
    	 */
    	public boolean isNoted() {
    		return noted;
    	}
    		
    	private boolean isTwoHanded;
    	
    	/**
    	 * Checks if item is two-handed
    	 */
    	public boolean isTwoHanded() {
    		return isTwoHanded;
    	}
    	
    	private boolean weapon;
    	
    	public boolean isWeapon() {
    		return weapon;
    	}
    	
    	private EquipmentType equipmentType = EquipmentType.WEAPON;
    	
    	public EquipmentType getEquipmentType() {
    		return equipmentType;
    	}
    	
    	/**
    	 * Checks if item is full body.
    	 */
    	public boolean isFullBody() {
    		return equipmentType.equals(EquipmentType.PLATEBODY);
    	}
    	
    	/**
    	 * Checks if item is full helm.
    	 */
    	public boolean isFullHelm() {
    		return equipmentType.equals(EquipmentType.FULL_HELMET);
    	}
    	
    	private double[] bonus = new double[18];
    	
    	public double[] getBonus() {
    		return bonus;
    	}
    	
    	private int[] requirement = new int[25];
    
    	public int[] getRequirement() {
    		return requirement;
    	}
    	
    	private enum EquipmentType {
    		HAT(Equipment.HEAD_SLOT),
    		CAPE(Equipment.CAPE_SLOT),
    		SHIELD(Equipment.SHIELD_SLOT),
    		GLOVES(Equipment.HANDS_SLOT),
    		BOOTS(Equipment.FEET_SLOT),
    		AMULET(Equipment.AMULET_SLOT),
    		RING(Equipment.RING_SLOT),
    		ARROWS(Equipment.AMMUNITION_SLOT),
    		FULL_MASK(Equipment.HEAD_SLOT),
    		FULL_HELMET(Equipment.HEAD_SLOT),
    		BODY(Equipment.BODY_SLOT),
    		PLATEBODY(Equipment.BODY_SLOT),
    		LEGS(Equipment.LEG_SLOT),
    		WEAPON(Equipment.WEAPON_SLOT);
    		
    		private EquipmentType(int slot) {
    			this.slot = slot;
    		}
    		
    		private int slot;
    	}
    	
    	@Override
    	public String toString() {
    		return "[ItemDefinition(" + id + ")] - Name: " + name + "; equipment slot: " + getEquipmentSlot() + "; value: "
    				+ value + "; stackable ? " + Boolean.toString(stackable) + "; noted ? " + Boolean.toString(noted) + "; 2h ? " + isTwoHanded;
    	}
    	
    	public static int getItemId(String itemName) {
    		for (int i = 0; i < MAX_AMOUNT_OF_ITEMS; i++) {
    			if (definitions[i] != null) {
    				if (definitions[i].getName().equalsIgnoreCase(itemName)) {
    					return definitions[i].getId();
    				}
    			}
    		}
    		return -1;
    	}
    }

    Thank you for taking the time to read this post.

    Pat

    Figured it out. Only took a few hours of pain and agony
    Reply With Quote  
     

  2. #2  
    Community Veteran


    arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,833
    Thanks given
    187
    Thanks received
    306
    Discord
    View profile
    Rep Power
    770
    try to do:
    Code:
    					if(value != null)
    					definition.name = value;
    instead of:
    Code:
    					if(value == null)
    						continue;
    					definition.name = value;


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  3. #3  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by arch337 View Post
    try to do:
    Code:
    					if(value != null)
    					definition.name = value;
    instead of:
    Code:
    					if(value == null)
    						continue;
    					definition.name = value;
    won't make a difference the error here i believe is "definition" is null
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,136
    Thanks given
    233
    Thanks received
    798
    Discord
    View profile
    Rep Power
    1575
    Quote Originally Posted by Spooky View Post
    won't make a difference the error here i believe is "definition" is null
    Yep

    Put
    Code:
    System.out.println(id);
    Under
    Code:
    case "item id":
        int id = Integer.valueOf(value);
    Then run,
    the last id printed will be the one before the one with the error.

    Then in items.txt search for that id, the one after will have a "name: whateever" but will be missing a "item id: ..."
    Reply With Quote  
     

  6. #5  
    Community Veteran


    arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,833
    Thanks given
    187
    Thanks received
    306
    Discord
    View profile
    Rep Power
    770
    Quote Originally Posted by Spooky View Post
    won't make a difference the error here i believe is "definition" is null
    Could be yes, really hard to tell from the mess.


    "A fail act is something you do regular, but a dumb act is something you can learn from"
    Spoiler for Problem?:
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Oct 2015
    Posts
    1
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by paepay1023 View Post
    I have never experienced this error and it's causing all of my items to no longer have requirements, stats, etc. I am hoping it's something simple.


    My Error:

    Code:
    Sep 07, 2018 3:05:12 AM com.arlania.GameServer main
    INFO: Initializing the loader...
    Exception in thread "GameLoadingThread" java.lang.NullPointerException
    	at com.arlania.model.definitions.ItemDefinition.init(ItemDefinition.java:75)
    	at com.arlania.GameLoader.lambda$5(GameLoader.java:129)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)

    Below is itemDefinition.java
    The line that is red and larger text is the line with the error.

    Code:
    package com.arlania.model.definitions;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    
    import com.arlania.model.container.impl.Equipment;
    
    /**
     * This file manages every item definition, which includes
     * their name, description, value, skill requirements, etc.
     * 
     * @author relex lawl
     */
    
    public class ItemDefinition {
    	
    	/**
    	 * The directory in which item definitions are found.
    	 */
    	private static final String FILE_DIRECTORY = "./data/def/txt/items.txt";
    
    	/**
    	 * The max amount of items that will be loaded.
    	 */
    	private static final int MAX_AMOUNT_OF_ITEMS = 22694;
    	
    	/**
    	 * ItemDefinition array containing all items' definition values.
    	 */
    	private static ItemDefinition[] definitions = new ItemDefinition[MAX_AMOUNT_OF_ITEMS];
    	
    	/**
    	 * Loading all item definitions
    	 */
    	public static void init() {
    		ItemDefinition definition = definitions[0];
    		try {
    			File file = new File(FILE_DIRECTORY);
    			BufferedReader reader = new BufferedReader(new FileReader(file));
    			String line;
    			while ((line = reader.readLine()) != null) {
    				if (line.contains("inish")) {
    					definitions[definition.id] = definition;
    					continue;
    				}
    				String[] args = line.split(": ");
    				if (args.length <= 1)
    					continue;
    				String token = args[0], value = args[1];
    				if (line.contains("Bonus[")) {
    					String[] other = line.split("]");
    					int index = Integer.valueOf(line.substring(6, other[0].length()));
    					double bonus = Double.valueOf(value);
    					definition.bonus[index] = bonus;
    					continue;
    				}
    				if (line.contains("Requirement[")) {
    					String[] other = line.split("]");
    					int index = Integer.valueOf(line.substring(12, other[0].length()));
    					int requirement = Integer.valueOf(value);
    					definition.requirement[index] = requirement;
    					continue;
    				}
    				switch (token.toLowerCase()) {
    				case "item id":
    					int id = Integer.valueOf(value);
    					definition = new ItemDefinition();
    					definition.id = id;
    					break;
    				case "name":
    					if(value == null)
    						continue;
    					definition.name = value;
    					break;
    				case "examine":
    					definition.description = value;
    					break;
    				case "value":
    					int price = Integer.valueOf(value);
    					definition.value = price;
    					break;
    				case "stackable":
    					definition.stackable = Boolean.valueOf(value);
    					break;
    				case "noted":
    					definition.noted = Boolean.valueOf(value);
    					break;
    				case "double-handed":
    					definition.isTwoHanded = Boolean.valueOf(value);
    					break;
    				case "equipment type":
    					definition.equipmentType = EquipmentType.valueOf(value);
    					break;
    				case "is weapon":
    					definition.weapon = Boolean.valueOf(value);
    					break;
    				}
    			}
    			reader.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}	
    	
    	public static ItemDefinition[] getDefinitions() {
    		return definitions;
    	}
    	
    	/**
    	 * Gets the item definition correspondent to the id.
    	 * 
    	 * @param id	The id of the item to fetch definition for.
    	 * @return		definitions[id].
    	 */
    	public static ItemDefinition forId(int id) {
    		return (id < 0 || id > definitions.length || definitions[id] == null) ? new ItemDefinition() : definitions[id];
    	}
    	
    	/**
    	 * Gets the max amount of items that will be loaded
    	 * in Niobe.
    	 * @return	The maximum amount of item definitions loaded.
    	 */
    	public static int getMaxAmountOfItems() {
    		return MAX_AMOUNT_OF_ITEMS;
    	}
    	
    	/**
    	 * The id of the item.
    	 */
    	private int id = 0;
    	
    	/**
    	 * Gets the item's id.
    	 * 
    	 * @return id.
    	 */
    	public int getId() {
    		return id;
    	}
    	
    	/**
    	 * The name of the item.
    	 */
    	private String name = "None";
    	
    	/**
    	 * Gets the item's name.
    	 * 
    	 * @return name.
    	 */
    	public String getName() {
    		return name;
    	}
    	
    	/**
    	 * The item's description.
    	 */
    	private String description = "Null";
    	
    	/**
    	 * Gets the item's description.
    	 * 
    	 * @return	description.
    	 */
    	public String getDescription() {
    		return description;
    	}
    	
    	/**
    	 * Flag to check if item is stackable.
    	 */
    	private boolean stackable;
    	
    	/**
    	 * Checks if the item is stackable.
    	 * 
    	 * @return	stackable.
    	 */
    	public boolean isStackable() {
    		if(noted)
    			return true;
    		return stackable;
    	}
    	
    	/**
    	 * The item's shop value.
    	 */
    	private int value;
    	
    	/**
    	 * Gets the item's shop value.
    	 * 
    	 * @return	value.
    	 */
    	public int getValue() {
    		return isNoted() ? ItemDefinition.forId(getId() - 1).value : value;
    	}
    	
    	/**
    	 * Gets the item's equipment slot index.
    	 * 
    	 * @return	equipmentSlot.
    	 */
    	public int getEquipmentSlot() {
    		return equipmentType.slot;
    	}
    	
    	/**
    	 * Flag that checks if item is noted.
    	 */
    	private boolean noted;
    	
    	/**
    	 * Checks if item is noted.
    	 * 
    	 * @return noted.
    	 */
    	public boolean isNoted() {
    		return noted;
    	}
    		
    	private boolean isTwoHanded;
    	
    	/**
    	 * Checks if item is two-handed
    	 */
    	public boolean isTwoHanded() {
    		return isTwoHanded;
    	}
    	
    	private boolean weapon;
    	
    	public boolean isWeapon() {
    		return weapon;
    	}
    	
    	private EquipmentType equipmentType = EquipmentType.WEAPON;
    	
    	public EquipmentType getEquipmentType() {
    		return equipmentType;
    	}
    	
    	/**
    	 * Checks if item is full body.
    	 */
    	public boolean isFullBody() {
    		return equipmentType.equals(EquipmentType.PLATEBODY);
    	}
    	
    	/**
    	 * Checks if item is full helm.
    	 */
    	public boolean isFullHelm() {
    		return equipmentType.equals(EquipmentType.FULL_HELMET);
    	}
    	
    	private double[] bonus = new double[18];
    	
    	public double[] getBonus() {
    		return bonus;
    	}
    	
    	private int[] requirement = new int[25];
    
    	public int[] getRequirement() {
    		return requirement;
    	}
    	
    	private enum EquipmentType {
    		HAT(Equipment.HEAD_SLOT),
    		CAPE(Equipment.CAPE_SLOT),
    		SHIELD(Equipment.SHIELD_SLOT),
    		GLOVES(Equipment.HANDS_SLOT),
    		BOOTS(Equipment.FEET_SLOT),
    		AMULET(Equipment.AMULET_SLOT),
    		RING(Equipment.RING_SLOT),
    		ARROWS(Equipment.AMMUNITION_SLOT),
    		FULL_MASK(Equipment.HEAD_SLOT),
    		FULL_HELMET(Equipment.HEAD_SLOT),
    		BODY(Equipment.BODY_SLOT),
    		PLATEBODY(Equipment.BODY_SLOT),
    		LEGS(Equipment.LEG_SLOT),
    		WEAPON(Equipment.WEAPON_SLOT);
    		
    		private EquipmentType(int slot) {
    			this.slot = slot;
    		}
    		
    		private int slot;
    	}
    	
    	@Override
    	public String toString() {
    		return "[ItemDefinition(" + id + ")] - Name: " + name + "; equipment slot: " + getEquipmentSlot() + "; value: "
    				+ value + "; stackable ? " + Boolean.toString(stackable) + "; noted ? " + Boolean.toString(noted) + "; 2h ? " + isTwoHanded;
    	}
    	
    	public static int getItemId(String itemName) {
    		for (int i = 0; i < MAX_AMOUNT_OF_ITEMS; i++) {
    			if (definitions[i] != null) {
    				if (definitions[i].getName().equalsIgnoreCase(itemName)) {
    					return definitions[i].getId();
    				}
    			}
    		}
    		return -1;
    	}
    }

    Thank you for taking the time to read this post.

    Pat

    Figured it out. Only took a few hours of pain and agony


    What is the fix to this?? I've been at it for a while tonight and I CANNOT figure it out. I look through the entire Item.txt file and found nothing. Please help me!
    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. Need help with java.lang.error
    By noob121 in forum Help
    Replies: 0
    Last Post: 04-09-2016, 05:38 AM
  2. Replies: 6
    Last Post: 02-07-2009, 01:03 AM
  3. Need help with an error in NPCHandler.
    By Anx Ziety in forum Help
    Replies: 4
    Last Post: 11-10-2008, 04:15 AM
  4. need help with some Errors
    By afroman in forum Help
    Replies: 0
    Last Post: 11-09-2008, 10:04 AM
  5. im need help with java
    By ziukis in forum Help
    Replies: 6
    Last Post: 11-01-2008, 12:44 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
  •