Results 1 to 3 of 3

Thread: Coding error :L

  1. #1
    mattd25 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Unhappy Coding error :L

    So ive got a basic code that is throwing the following error :- java.lang.ArrayIndexOutOfBoundsEception

    Apparently The getIndexs array is too small to support 19 indexes and im not sure how to fix it.

    This is only a code snippet but you can see the return (lastArchiveId * 256 + Cache.STORE.getIndexes()[19] where the issue crops up


    Java Code:
    //22314
    
    
    	public static final int getItemDefinitionsSize() {
    		int lastArchiveId = Cache.STORE.getIndexes()[19].getLastArchiveId();
    		return (lastArchiveId * 256 + Cache.STORE.getIndexes()[19]
    				.getValidFilesCount(lastArchiveId)) - 22314;
    	}
    	
    	public static boolean itemExists(int id) {
    		if(id >= getItemDefinitionsSize()) //setted because of custom items
    			return false;
    		return Cache.STORE.getIndexes()[19].fileExists(id >>> 8, 0xff & id);
    	}

  2. #2
    mattd25 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: Coding error :L

    Here is more on the specific error :-

    [Launcher] Initing Cache...
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 19
    * * * *at com.rs.utils.Utils.getItemDefinitionsSize(Utils.ja va:268)
    * * * *at com.rs.cache.loaders.ItemsEquipIds.init(ItemsEquip Ids.java:13)
    * * * *at com.rs.Launcher.main(Launcher.java:64)
    Press any key to continue . . .

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default Re: Coding error :L

    Quote Originally Posted by mattd25 View Post
    Here is more on the specific error :-

    [Launcher]Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 19
    The index of an array is always zero based. So if you initialize an array of int with [10] the first element in the array will have the index 0 and the last element the index 9! Using an index greater than 9 will cause a java.lang.ArrayIndexOutOfBoundsException. So be careful with your indexes bounds!

Similar Threads

  1. coding error-please help
    By Michael2 in forum New To Java
    Replies: 3
    Last Post: 07-29-2012, 11:30 PM
  2. A newbie to Java needing help on coding error
    By Turo in forum New To Java
    Replies: 5
    Last Post: 08-28-2011, 06:11 AM
  3. Error in coding
    By bamagirl31 in forum New To Java
    Replies: 3
    Last Post: 05-11-2011, 07:31 PM
  4. Replies: 4
    Last Post: 10-25-2010, 04:49 PM
  5. Error in my coding
    By one198 in forum New To Java
    Replies: 2
    Last Post: 10-13-2007, 06:07 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
  •