Cardozz 46 Share Posted July 4, 2016 Hi there, I got a weird error: my method calls for a widget, and i am 1000000% sure it is NOT null, still it returns null (i checked it by debugging the code with logs). Heres the code: WidgetChild someWidget = getWidgets().getWidgetChild(84, 26); if(someWidget != null){ // some code } else log("BONUS WIDGET == NULL"); It must have something to do with either the widget or the null check. I also tried someWidget.isVisible() and someWidget.isHidden() but they both gave me a nullpointer error. The weirdest part of all is that above this code i have likely exact the same code with another widget, but this one executes well! Thanks for any help in advance Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted July 4, 2016 Hi there, I got a weird error: my method calls for a widget, and i am 1000000% sure it is NOT null, still it returns null (i checked it by debugging the code with logs). Heres the code: WidgetChild someWidget = getWidgets().getWidgetChild(84, 26); if(someWidget != null){ // some code } else log("BONUS WIDGET == NULL"); It must have something to do with either the widget or the null check. I also tried someWidget.isVisible() and someWidget.isHidden() but they both gave me a nullpointer error. The weirdest part of all is that above this code i have likely exact the same code with another widget, but this one executes well! Thanks for any help in advance Did you try looking at the widget in the widget debugger while checking it? Link to comment Share on other sites More sharing options...
Cardozz 46 Author Share Posted July 4, 2016 Did you try looking at the widget in the widget debugger while checking it? Yes, i am very sure i got the right widget. It sometimes works if i start the script with the widget already visible. I got the getText() a few times and it was the correct widget. i forgot to mention the method itself looks like this: private boolean hasRequirements(){ //widget variables if(widget1 == null){ //CODE } if(widget1 != null){ //CODE } return false; } So basically if the widget is always null, the first part of the method will always execute. So i guess the widget is always returning null, but i am sure its not null.. Maybe i'm calling the widget incorrectly? Because in: "WidgetChild someWidget = getWidgets().getWidgetChild(84, 26);" 84 is the parent widget and 26 is the child widget. Link to comment Share on other sites More sharing options...
Pandemic 2702 Share Posted July 4, 2016 That's correct, could you paste the whole stack trace here Thanks Link to comment Share on other sites More sharing options...
Cardozz 46 Author Share Posted July 4, 2016 That's correct, could you paste the whole stack trace here Thanks It's just giving a nullpointer exception if i don't check for nullpointers. Otherwise, like the code above, it just skips the body and logs my manual log debug that the widget was null by doing: if(someWidget != null){ // some code } else log("BONUS WIDGET == NULL"); And the widget debugger even notices the widgetchild, so it is not null at the time i call it.. I've checked that by refreshing the widget debugger when it should/shouldn't be visible Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted July 4, 2016 Just post what the exception throws if you don't test for it Link to comment Share on other sites More sharing options...
Cardozz 46 Author Share Posted July 4, 2016 That's correct, could you paste the whole stack trace here Thanks Just post what the exception throws if you don't test for it [ERROR]21:53:53: Exception has occurred while running! Please report error to developer if problem persists! [ERROR]21:53:53: java.lang.NullPointerException at main.RevisionMain.hasRequirementsr(RevisionMain.java:58) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:187) at java.lang.Thread.run(Unknown Source) Note: i made it nullpoint on purpose, else it wont even show a stack trace. Link to comment Share on other sites More sharing options...
Pandemic 2702 Share Posted July 4, 2016 Double check the widget parent and child ID, and if they're correct you can try getWidgets().getWidget(84).getChild(26) (but I don't think that'll make a difference). Link to comment Share on other sites More sharing options...
Cardozz 46 Author Share Posted July 4, 2016 Double check the widget parent and child ID, and if they're correct you can try getWidgets().getWidget(84).getChild(26) (but I don't think that'll make a difference). I have quadruple checked the widget child ID. It worked before with the SAME id, but since i ripped the nested code apart (it's correct, no flaws) it needs like 5 loops to see that the child is not null. Oh and i already did that man, i got the above error with getWidgets().getWidget(84).getChild(26). Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted July 4, 2016 I have quadruple checked the widget child ID. It worked before with the SAME id, but since i ripped the nested code apart (it's correct, no flaws) it needs like 5 loops to see that the child is not null. Oh and i already did that man, i got the above error with getWidgets().getWidget(84).getChild(26). Just curious... not sure it'll help try getting the 84 widget and null checking it and then grab the child... tho..m getChild should throw an error then shouldn't it... hmm Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.