Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help with classes, Java [class included]

Featured Replies

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.  


 

Edited by lol0

 

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 by Chris

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

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 by LoudPacks

  • Author

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 by lol0

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.