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
  • getting NullPointException at getWidget()


    henrique190

    Recommended Posts

    Posted

    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);
    
    Posted

    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

    Posted

    Thanks Fran i will try  identify the that null points, thanks for the supporting

    Posted

    ahhh, Some competition.

    Good luck ^_^ 

    Posted

    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

    Posted

    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. :)

    Posted

    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.

    Posted

    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.

    ^ That too, thanks. :)

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.