Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • getting NullPointException at getWidget()


    henrique190
     Share

    Recommended Posts

    Hi happy day for yours

     

    im getting JavaNullPointException on my script in alot of parts, any may help-me?

     

    at error return on script i this:

    java.lang.NullPointerException
    	at MoneyMaking.KarambwanBuyer.onLoop(KarambwanBuyer.java:304)
    	at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:167)
    	at java.lang.Thread.run(Unknown Source)
    
    

    i will put the code was return this error:

    NPC Viajador = getNpcs().closest("Trader crewmember");
    			if (Viajador != null) {
    				Viajador.interact("Charter");
    
    			}
    
    			 Calculations.random(3400, 5000);
               
                    
               	getWidgets().getWidget(95).getChild(16).interact();	
                        
    
               	
               	
               	
                	
            			sleepUntil(new Condition() {
            				
            				@Override
            				public boolean verify() {
            					// TODO Auto-generated method stub
            					 return getWidgets().getChildWidget(95,16) == null
            							|| (getWidgets().getChildWidget(192,16) != null && getWidgets()
            							.getChildWidget(95,16).isVisible());
            				}
            			}, Calculations.random(3400, 5000));
    
    			// getWidgets().getChildWidget(95,16).interact(null);
    			Calculations.random(4000, 5000);
    
    Link to comment
    Share on other sites

    I see the mistake, but let me provide you a snippet to see if you can catch the error :P

    		WidgetChild randomWindow = getWidgets().getChildWidget(325, 71); //Window's wChild -> "X" (Close button)
    		if(randomWindow != null) { //If the window is not null
    			if(randomWindow.isVisible()) { //and is also visible
    					log("Executing: Closing WidgetChild randomWindow"); //random log
    					randomWindow.interact("Close"); //interact with an ACTION
    					sleep(300); //random sleep
    				}
    			}
    		}
    
    

    A null pointer exception is basically when you try to use a reference that points to no location in memory (null), calling a method on a null reference or trying to access a field of a null reference will trigger a NPE
     

    String ex = null;
    System.out.println(ex.toString()); // NullPointerException will be thrown
    

    Start by identifying the null values

    Link to comment
    Share on other sites

    Thanks Zawy  i will need! haha

     

    Edited:

     

    i was fixed my problem using this code, I hope my questions may help others users,

    Thansk Sr's

    :D

    if (getWidgets().getChildWidget(95,16) != null
    					&& getWidgets().getChildWidget(95,16).isVisible()) {
    				if (getWidgets().getChildWidget(95,16).interact()) {
    					sleepUntil(new Condition() {
    						public boolean verify() {
    							return getWidgets().getChildWidget(95,16) == null
    									|| (getWidgets().getChildWidget(95,16) != null && getWidgets()
    											.getChildWidget(95,16).isVisible());
    						}
    					}, Calculations.random(1800, 2400));
    				}
    			}
    
    

    i was based this code on the code of vlad's Aio WoodCutter, Thanks Vlad's for openSource

    Edited by henrique190
    Link to comment
    Share on other sites

    Rather than doing getWidgets().getChildWidget every time you should set it to a variable. That'll lower the CPU usage of the script a bit.

    So it'd be like

    WidgetChild wc = getWidgets().getChildWidget(a,b );

    if(wc != null && wc.isVisible()){
        wc.interact(whatever);
    }

     

    calling the getChildWidget every time will bump CPU and memory up, lowering the efficiency and usability of your script by just a bit.

    You might not notice it on your own but if people run 3 accounts on one client with it, they'll notice. :)

    Link to comment
    Share on other sites

    Rather than doing getWidgets().getChildWidget every time you should set it to a variable. That'll lower the CPU usage of the script a bit.

    So it'd be like

    WidgetChild wc = getWidgets().getChildWidget(a, B);

    if(wc != null && wc.isVisible()){

        wc.interact(whatever);

    }

     

    calling the getChildWidget every time will bump CPU and memory up, lowering the efficiency and usability of your script by just a bit.

    You might not notice it on your own but if people run 3 accounts on one client with it, they'll notice. :)

     

    You forgot to mention you can get a null value sometimes and a non-null value sometimes too by calling it multiple times making the null check useless.

    Edited by Vlad
    Link to comment
    Share on other sites

     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.