Satire Posted December 13, 2016 Share Posted December 13, 2016 (edited) Ok before anyone laughs, I'm new to Java and I seriously have no idea what's wrong. This should work, works very well in c#. I have a class herehttp://pastebin.com/UPUdfhdxAnd I wanted to call the function by making a new instance of that class MakeMoneyHandler moneyhandler = new MakeMoneyHandler(); moneyhandler.Mining(0); However, when I run it, I get this [ERROR][bot #1][12/13 03:50:13 PM]: Error in script executor! java.lang.NullPointerException at org.osbot.rs07.script.MethodProvider.log(lp:841) at MakeMoneyHandler.Mining(MakeMoneyHandler.java:22) at main.onLoop(main.java:824) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(qi:31) at java.lang.Thread.run(Unknown Source) There is nothing wrong with the code as I copied it to main and it all worked 100% fine.Don't worry about the code itself and say "this check is wrong", I know there are some errors and I'm re-writing it as I post this. I just wanted a seperate class that handles my functions. Also don't worry about the while loop, It was there for another test. Edited December 13, 2016 by lol0 Quote Link to comment Share on other sites More sharing options...
Chris Posted December 13, 2016 Share Posted December 13, 2016 (edited) Ok before anyone laughs, I'm new to Java and I seriously have no idea what's wrong. This should work, works very well in c#. I have a class here http://pastebin.com/UPUdfhdx And I wanted to call the function by making a new instance of that class MakeMoneyHandler moneyhandler = new MakeMoneyHandler(); moneyhandler.Mining(0); However, when I run it, I get this [ERROR][bot #1][12/13 03:50:13 PM]: Error in script executor! java.lang.NullPointerException at org.osbot.rs07.script.MethodProvider.log(lp:841) at MakeMoneyHandler.Mining(MakeMoneyHandler.java:22) at main.onLoop(main.java:824) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(qi:31) at java.lang.Thread.run(Unknown Source) There is nothing wrong with the code as I copied it to main and it all worked 100% fine. Don't worry about the code itself and say "this check is wrong", I know there are some errors and I'm re-writing it as I post this. I just wanted a seperate class that handles my functions. Also don't worry about the while loop, It was there for another test. public class MakeMoneyHandler { private MethodProvider ctx; public MakeMoneyHandler(MethodProvider ctx){ this.ctx = ctx; } public void killShit(){ ctx.log("I killed the game homie"); } } public Main extends Script{ private MakeMoneyHandler = new MakeMoneyHandler(this); } Edited December 13, 2016 by Chris Quote Link to comment Share on other sites More sharing options...
Satire Posted December 13, 2016 Author Share Posted December 13, 2016 public class MakeMoneyHandler { private MethodProvider ctx; public MakeMoneyHandler(MethodProvider ctx){ this.ctx = ctx; } public void killShit(){ ctx.log("I killed the game homie"); } } public Main extends Script{ private MakeMoneyHandler = new MakeMoneyHandler(this); } You legend! You just saved main from going to 3k+ lines. Quote Link to comment Share on other sites More sharing options...
LoudPacks Posted December 13, 2016 Share Posted December 13, 2016 (edited) You legend! You just saved main from going to 3k+ lines. Or you could also create a separate class instead of using nested classes. I would look into a task based system if you want to be more organized. There's several tutorials on the site about how to do this. Basically each 'task' has its own class and then in your main class you just add a new instance of each task to the task manager, which loops through each task and executes it if it should be active, which is determined by a method inside each task class, usually isActive() which would return a boolean depending on the condition you place within said method. Then you can have a task / separate class for banking per say, and another for combat, etc. in Main.java: @[member='Override'] public void onStart() { Settings settings = new Settings(this); settings.setCallback(b -> { addTask(new SwapTask(this)); addTask(new TradeTask(this)); }); } in TradeTask.java for example: package com.loudpacks.script; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.utility.ConditionalSleep; import com.loudpacks.api.Task; import com.loudpacks.gui.Settings; public class TradeTask extends Task { private final Area RUINS = new Area(2386, 4829, 2415, 4855); private final Area INNER_RUINS = new Area(2404, 4837, 2395, 4845); private final Area PORTAL_AREA = new Area(2402, 4833, 2397, 4836); public TradeTask(MethodProvider api){ super(api); } @[member=Override] public boolean isActive() { return RUINS.contains(api.myPlayer()); } @[member=Override] public void onStart() { } @[member=Override] public void onLoop() { // code to execute when active } @[member=Override] public void onEnd() { } } Edited December 13, 2016 by LoudPacks 1 Quote Link to comment Share on other sites More sharing options...
Satire Posted December 13, 2016 Author Share Posted December 13, 2016 (edited) Or you could also create a separate class instead of using nested classes. I would look into a task based system if you want to be more organized. There's several tutorials on the site about how to do this. Basically each 'task' has its own class and then in your main class you just add a new instance of each task to the task manager, which loops through each task and executes it if it should be active, which is determined by a method inside each task class, usually isActive() which would return a boolean depending on the condition you place within said method. Then you can have a task / separate class for banking per say, and another for combat, etc. I'll take a look into this then. Damn this is gonna take a while to fix up. Thank you! Edited December 13, 2016 by lol0 Quote Link to comment Share on other sites More sharing options...