Thread: [PI] Help with a NullPointerException

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 [PI] Help with a NullPointerException 
    Donator
    Will_'s Avatar
    Join Date
    Oct 2013
    Age
    26
    Posts
    153
    Thanks given
    14
    Thanks received
    8
    Rep Power
    11
    I've spent the better part of a couple of hours over the last 2 days trying to diagnose this issue, and I've done the best of my ability to try to find the cause of the issue, but to no avail. I'm not sure why this is happening at this point. I've highlighted part of the offending code in red below where I'm beginning to think issue lies as of right now, but figured I'd still come for advice just in case I'm barking up the wrong tree (again).

    Code:
    for (final NPCLoot loot : NPCLootTable.forID(npcs[i].npcType).getGeneratedLoot((int) addChance)) {
    				Server.itemHandler.createGroundItem(c, loot.getItemID(), npcs[i].absX, npcs[i].absY, Misc.random(loot.getMinAmount(), loot.getMaxAmount()), c.playerId);
    			}
    Spoiler for Exception:
    Attached image


    The problem I'm having with diagnosing this is that sometimes it works flawlessly, other times it'll throw that exception and crash the server and I haven't been able to figure out what is happening when it runs into the problem. I've even tried catching the NullPointerException with a try/catch statement, but that still didn't let me keep the server from crashing and give me the cause of the problem.
    Quote Originally Posted by Liam_ View Post
    I wouldn't be surprised if some of you just come here for content and not contribute to rune-server or the community in anyway.
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Sep 2010
    Posts
    57
    Thanks given
    7
    Thanks received
    0
    Rep Power
    1
    You should upload that lines which is mentioned in error
    Reply With Quote  
     

  3. #3  
    Donator
    Will_'s Avatar
    Join Date
    Oct 2013
    Age
    26
    Posts
    153
    Thanks given
    14
    Thanks received
    8
    Rep Power
    11
    Quote Originally Posted by adrijusxx View Post
    You should upload that lines which is mentioned in error
    What do you think the code I posted is....
    Quote Originally Posted by Liam_ View Post
    I wouldn't be surprised if some of you just come here for content and not contribute to rune-server or the community in anyway.
    Attached image
    Reply With Quote  
     

  4. #4  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Quote Originally Posted by Will_ View Post
    What do you think the code I posted is....
    What is your "addChance" variable?


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

  5. #5  
    Donator
    Will_'s Avatar
    Join Date
    Oct 2013
    Age
    26
    Posts
    153
    Thanks given
    14
    Thanks received
    8
    Rep Power
    11
    Quote Originally Posted by arch337 View Post
    What is your "addChance" variable?
    Code:
    final double addChance = c.playerEquipment[c.playerRing] == 2572 ? 1.25 : 1;
    Quote Originally Posted by Liam_ View Post
    I wouldn't be surprised if some of you just come here for content and not contribute to rune-server or the community in anyway.
    Attached image
    Reply With Quote  
     

  6. #6  
    Registered Member Stevenhax's Avatar
    Join Date
    Jul 2014
    Posts
    387
    Thanks given
    55
    Thanks received
    64
    Rep Power
    42
    Post the full code with proper line numbers and we can probably help you,
    alternatively post line 93 and maybe we can help you.
    Reply With Quote  
     

  7. #7  
    Donator
    Will_'s Avatar
    Join Date
    Oct 2013
    Age
    26
    Posts
    153
    Thanks given
    14
    Thanks received
    8
    Rep Power
    11
    Quote Originally Posted by Stevenhax View Post
    Post the full code with proper line numbers and we can probably help you,
    alternatively post line 93 and maybe we can help you.
    Edit: Here you go. This is the method from line 93 of NPCLootTable. I'm not at my computer right now, but anything you need I should be able to dig up.

    Code:
    private ArrayList<NPCLoot> getRolledLoot(final double chanceOffset) {
    		//A 'copy' of the dynamicDrops.
    		final ArrayList<NPCLoot> temp = new ArrayList<>(dynamicDrops);
    		final ArrayList<NPCLoot> rolledLoot = new ArrayList<>();
    		final Random random = new Random();
    		
    		for (int i = 0; i < rolls; i++) {
    			final double roll = (random.nextDouble() * ROLL_MULTIPLIER);
    			//Randomizes the loot ArrayList copy.
    			Collections.shuffle(temp);
    			
    			for (final NPCLoot loot : temp) {
    				final double _chanceOffset = (loot.getHitRollCeil() * chanceOffset);
    				
    				if ((loot.getHitRollCeil() + _chanceOffset) >= roll) {
    					rolledLoot.add(loot);
    					temp.remove(loot);
    					break;
    				}
    			}
    		}
    		return rolledLoot;
    	}
    Last edited by Will_; 12-18-2018 at 01:02 AM.
    Quote Originally Posted by Liam_ View Post
    I wouldn't be surprised if some of you just come here for content and not contribute to rune-server or the community in anyway.
    Attached image
    Reply With Quote  
     

  8. #8  
    Community Veteran


    Arch337's Avatar
    Join Date
    Sep 2008
    Posts
    2,950
    Thanks given
    210
    Thanks received
    349
    Rep Power
    1376
    Quote Originally Posted by Will_ View Post
    Edit: Here you go. This is the method from line 93 of NPCLootTable. I'm not at my computer right now, but anything you need I should be able to dig up.

    Code:
    private ArrayList<NPCLoot> getRolledLoot(final double chanceOffset) {
    		//A 'copy' of the dynamicDrops.
    		final ArrayList<NPCLoot> temp = new ArrayList<>(dynamicDrops);
    		final ArrayList<NPCLoot> rolledLoot = new ArrayList<>();
    		final Random random = new Random();
    		
    		for (int i = 0; i < rolls; i++) {
    			final double roll = (random.nextDouble() * ROLL_MULTIPLIER);
    			//Randomizes the loot ArrayList copy.
    			Collections.shuffle(temp);
    			
    			for (final NPCLoot loot : temp) {
    				final double _chanceOffset = (loot.getHitRollCeil() * chanceOffset);
    				
    				if ((loot.getHitRollCeil() + _chanceOffset) >= roll) {
    					rolledLoot.add(loot);
    					temp.remove(loot);
    					break;
    				}
    			}
    		}
    		return rolledLoot;
    	}
    I assume rolledLoot is nulled which turn getGeneratedLoot into null which cause your issue.


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

  9. #9  
    Donator
    Will_'s Avatar
    Join Date
    Oct 2013
    Age
    26
    Posts
    153
    Thanks given
    14
    Thanks received
    8
    Rep Power
    11
    Quote Originally Posted by arch337 View Post
    I assume rolledLoot is nulled which turn getGeneratedLoot into null which cause your issue.
    rolledLoot shouldn't be null because the drop table has items in it. There's a staticDrops table for items that should always drop, and then dynamicDrops which are rolled by % chance. Also as I said, sometimes it works and both drops show up, works when only the 100% drop drops. I haven't been able to debug this to the point of finding out what is exactly happening for anything to return null.
    Quote Originally Posted by Liam_ View Post
    I wouldn't be surprised if some of you just come here for content and not contribute to rune-server or the community in anyway.
    Attached image
    Reply With Quote  
     

  10. #10  
    The One And Only

    01053's Avatar
    Join Date
    Apr 2011
    Age
    28
    Posts
    2,887
    Thanks given
    417
    Thanks received
    885
    Rep Power
    856
    For starters I don't know why you're casting it to an int makes it being a decimal number redundant because it will round it to the closest whole number so it'll be equal to 1 whether they have the ring or not.

    Code:
        private static boolean hasRow;
        private static double addChance = hasRow ? 1.25 : 1;
    
        private static boolean getRowEquipped() {
            return hasRow;
        }
    
        public static void main(String[] args) {
            System.out.println("Ring of Wealth: " + getRowEquipped() + "\tDrop Chance: " + (int) addChance);
            hasRow = true;
            System.out.println("Ring of Wealth: " + getRowEquipped() + "\tDrop Chance: " + (int) addChance);
        }
    Output:

    Code:
    Ring of Wealth: false	Drop Chance: 1
    Ring of Wealth: true	Drop Chance: 1
    As for the main problem,

    Can you please highlight line 93 & 116 of NPCLootTable.


    Reply With Quote  
     

Page 1 of 2 12 LastLast

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. [PI] Help with a Command?
    By 'Glory in forum Help
    Replies: 5
    Last Post: 11-01-2010, 12:24 PM
  2. [PI] Help with commands
    By EricFtw in forum Help
    Replies: 4
    Last Post: 10-13-2010, 02:47 PM
  3. [PI] help with models please,
    By GOOD in forum Help
    Replies: 4
    Last Post: 10-07-2010, 04:41 PM
  4. [PI] Help with this Please!
    By 'Glory in forum Help
    Replies: 0
    Last Post: 10-04-2010, 05:24 AM
  5. [PI] Help with xteletome needed..
    By PaNiiC Joe in forum Help
    Replies: 4
    Last Post: 05-31-2010, 05:59 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •