Jump to content

ERROR when starting script?


Bigpoppa21

Recommended Posts

[ERROR][01/22 08:08:24 PM]: Failed to start script [FlaxSpinner]

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.osbot.coM1.run(ve:146)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NullPointerException

at Main.<init>(Main.java:18)

... 8 more

 

 

Prints this out when I try to start a script I've been working on. Do I need to post my script up here also?

Link to comment
Share on other sites


import org.osbot.rs07.api.map.Position;

import org.osbot.rs07.api.model.Player;

import org.osbot.rs07.api.model.RS2Object;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import org.osbot.rs07.utility.Area;

import org.osbot.rs07.api.Client;

import org.osbot.rs07.api.Interfaces;

import java.awt.*;

@ScriptManifest(author = "ME", info = "My second script", name = "FlaxSpinner", version = 0, logo = "")

public class Main extends Script {

@Override

public void onStart() {

log("Let's get started!");

}

final int BANK_BOOTH_ID = 18491;

RS2Object bankBooth = objects.closest("Bank booth");

private static final Area SPIN_AREA = new Area(3208, 3212, 3211, 3216);

RS2Object Spinning_wheel = objects.closest("Spinning wheel");

Interfaces Inter = objects.getInterfaces();

Client client = objects.getClient();

Player player = myPlayer();

RS2Object Stair_Case = objects.closest("Staircase");

RS2Object Door = objects.closest("Door");

private enum State{

SPIN, BANK, WALK_TO_WHEEL, WALK_TO_BANK;

}

private State getState() {

if (inventory.contains("Flax") && SPIN_AREA.contains(player.getPosition())){

return State.SPIN;

}

else if(!inventory.contains("Flax") && SPIN_AREA.contains(player.getPosition())){

return State.BANK;

}

else if(inventory.contains("Flax") && !SPIN_AREA.contains(player.getPosition())){

return State.WALK_TO_WHEEL;

}

else{

return State.WALK_TO_BANK;

}

}

private boolean checkDoorIsOpen(){

if(Door != null) {

for(String actions: Door.getDefinition().getActions()) {

if(actions.contains("Open")) {

return true;

}

}

}

return false;

}

@Override

public int onLoop() throws InterruptedException {

switch(getState()){

case SPIN:

outerIf:

if(!myPlayer().isAnimating()){

sleep(random(500, 1000));

if(!inventory.contains("Flax")){

sleep(random(600, 800));

break outerIf;

}

while(!player.isAnimating()){

sleep(random(50, 100));

Spinning_wheel.interact("Spin");

Inter.interactWithChild(459, 91, "Make X");

if (Inter.containingText("Enter amount:") != null){

sleep(random(1000,2000));

keyboard.typeString("99");

break outerIf;

}

}

}

break;

case BANK:

if(bankBooth != null){

if(bankBooth.interact("Bank")){

while(!bank.isOpen()){

sleep(random(250, 400));

}

bank.depositAll("Bow string");

if(bank.contains("Flax")){

bank.withdraw("Flax", 28);

}

else{

stop();

}

bank.close();

}

}

break;

case WALK_TO_BANK:

localWalker.walk(new Position(3208, 3214, 1));

if(checkDoorIsOpen()){

String status = "Opening the door";

Door.interact("Open");

}else if(!checkDoorIsOpen()){

sleep(random(500,700));

localWalker.walk(new Position(3205,3209,1));

if (Stair_Case != null){

Stair_Case.interact("Climb");

sleep(random(200,300));

Inter.interactWithChild(459, 91, "Climb up the stairs.");

localWalker.walk(new Position(3208,3220,2));

}

}

break;

case WALK_TO_WHEEL:

localWalker.walk(new Position(3205, 3209, 2));

if(Stair_Case != null){

Stair_Case.interact("Climb-down");

if(checkDoorIsOpen()){

String status = "Opening the door";

Door.interact("Open");

}else if(!checkDoorIsOpen()){

localWalker.walk(new Position(3209, 3213, 1));

}

}

break;

}

return random(200, 300);

}

@Override

public void onExit() {

log("Thanks for running my FlaxSpinner!");

}

@Override

public void onPaint(Graphics2D g) {

}

}

Link to comment
Share on other sites

Just reposted this - so it doesn't come up with that horrible white between the lines  ( http://gyazo.com/e58de3ce3ac286d198cb906a22e03d71 ) - Apologies if this is a problem just for me. 

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.Area;
import org.osbot.rs07.api.Client;
import org.osbot.rs07.api.Interfaces;
import java.awt.*;
 
 
@ScriptManifest(author = "ME", info = "My second script", name = "FlaxSpinner", version = 0, logo = "")
public class Main extends Script {
 
	
    @Override
    public void onStart() {
        log("Let's get started!");
    }
    
    final int BANK_BOOTH_ID = 18491;
	RS2Object bankBooth = objects.closest("Bank booth");
    private static final Area SPIN_AREA = new Area(3208, 3212, 3211, 3216);
    RS2Object Spinning_wheel = objects.closest("Spinning wheel");
	Interfaces Inter = objects.getInterfaces();
	Client client = objects.getClient();
	Player player = myPlayer();
	RS2Object Stair_Case = objects.closest("Staircase");
	RS2Object Door = objects.closest("Door");
    
    private enum State{
		SPIN, BANK, WALK_TO_WHEEL, WALK_TO_BANK;
	}
    
    
	private State getState() {
    	if (inventory.contains("Flax") && SPIN_AREA.contains(player.getPosition())){
    		return State.SPIN;
    	}
    	else if(!inventory.contains("Flax") && SPIN_AREA.contains(player.getPosition())){
    		return State.BANK;
    	}
    	else if(inventory.contains("Flax") && !SPIN_AREA.contains(player.getPosition())){
    		return State.WALK_TO_WHEEL;
    	}
    	else{
    		return State.WALK_TO_BANK;
    	}
	}
	
	private boolean checkDoorIsOpen(){ 
 
        if(Door != null) {
            for(String actions: Door.getDefinition().getActions()) {
                if(actions.contains("Open")) {
                    return true;
                }
            }
        }
        return false;
    }
 
    @Override
    public int onLoop() throws InterruptedException {
    	
    	switch(getState()){
    	
    	case SPIN:
    		outerIf:
    			if(!myPlayer().isAnimating()){
    				sleep(random(500, 1000));
    				if(!inventory.contains("Flax")){
    					sleep(random(600, 800));
    					break outerIf;
    				}
    				while(!player.isAnimating()){
    					sleep(random(50, 100));
    					Spinning_wheel.interact("Spin");
    	    			Inter.interactWithChild(459, 91, "Make X");
    	    			if (Inter.containingText("Enter amount:") != null){
    	    				sleep(random(1000,2000));
    	    				keyboard.typeString("99");
    	    				break outerIf;
    	    				}
    					}
    				}
    			
    		break;
    	case BANK:
    		
    		if(bankBooth != null){
    			if(bankBooth.interact("Bank")){
    				while(!bank.isOpen()){
    					sleep(random(250, 400));
    				}
    				bank.depositAll("Bow string");
    				if(bank.contains("Flax")){
    					bank.withdraw("Flax", 28);
    				}
    				else{
    					stop();
    				}
    				bank.close();
    			}
    		}
    		break;
    	case WALK_TO_BANK:
    		localWalker.walk(new Position(3208, 3214, 1));
    		if(checkDoorIsOpen()){
    			String status = "Opening the door";
    			Door.interact("Open");
    		}else if(!checkDoorIsOpen()){
    			sleep(random(500,700));
    			localWalker.walk(new Position(3205,3209,1));
    			if (Stair_Case != null){
    				Stair_Case.interact("Climb");
    				sleep(random(200,300));
    				Inter.interactWithChild(459, 91, "Climb up the stairs.");
    				localWalker.walk(new Position(3208,3220,2));
    			}
    			
    		}
    		break;
    	case WALK_TO_WHEEL:
    		localWalker.walk(new Position(3205, 3209, 2));
    		if(Stair_Case != null){
    			Stair_Case.interact("Climb-down");
    			if(checkDoorIsOpen()){
    				String status = "Opening the door";
    				Door.interact("Open");
    			}else if(!checkDoorIsOpen()){
    				localWalker.walk(new Position(3209, 3213, 1));
    			}
    			
    		}
    		break;
    	}
    	return random(200, 300);
    	
    }
    	
    	
    
    
 
    @Override
    public void onExit() {
        log("Thanks for running my FlaxSpinner!");
    }
 
    @Override
    public void onPaint(Graphics2D g) {
 
    }
    
	
 
}
Edited by Roar
Link to comment
Share on other sites

 

[ERROR][01/22 08:08:24 PM]: Failed to start script [FlaxSpinner]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.osbot.coM1.run(ve:146)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at Main.<init>(Main.java:18)
... 8 more
 
 
Prints this out when I try to start a script I've been working on. Do I need to post my script up here also?

 

 

 

 

Just reposted this - so it doesn't come up with that horrible white between the lines  ( http://gyazo.com/e58de3ce3ac286d198cb906a22e03d71 ) - Apologies if this is a problem just for me. 


    final int BANK_BOOTH_ID = 18491;
	RS2Object bankBooth = objects.closest("Bank booth");
    private static final Area SPIN_AREA = new Area(3208, 3212, 3211, 3216);
    RS2Object Spinning_wheel = objects.closest("Spinning wheel");
	Interfaces Inter = objects.getInterfaces();
	Client client = objects.getClient();
	Player player = myPlayer();
	RS2Object Stair_Case = objects.closest("Staircase");
	RS2Object Door = objects.closest("Door");
    
    

I feel like something is wrong here.

 

edit: i'm assuming you removed something before posting the script, a few lines somewhere, otherwise that error makes no sense

Edited by Isolate
Link to comment
Share on other sites

I don't recall removing anything from the script before posting ithuh.png What does the error mean?

 

Well the issue is that you are instantiating objects before the script even loads. You need to declare them in the scope then instantiate them in the onLoop()/onStart(). Something to this effect if you don't get what I mean:

class FlaxSpinner extends Script{

   public Player myPlayer;
   
   public void onLoop(){
        myPlayer = getPlayer(); //or whatever you call the method
   }

}

Hopefully you get the idea, you need to do this for all the objects created. This is bad practice assigning a new object every call of the loop so I would recommend you put it in a statement block where if you reach a certain area lets say then it will create the object.

if(myPlayer.isInArea(BANK)){
   bankBooth = objects.closest("bank booth");

   if(bankBooth != null){
      bankBooth.interact("Use");
   }
}

Don't copy n paste pulled the API from my head and it's not doubt wrong tongue.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...