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.

Java.lang.NullpointerException

Featured Replies

I am making a Chickenkiller script for educational purpose. it was running okay until i got the error in the screenshot:image.png.69205079d45fd803ad2bcd4876fb196e.png

I just dont see what im doing wrong. on google i found the following: "The NullPointerException (NPE) typically occurs when you declare a variable but did not create an object and assign it to the variable before trying to use the contents of the variable. So you have a reference to something that does not actually exist." i dont understand what it means can sombody help?

The code i was using:

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

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(name = "Chickenkiller", author = "Snatsbats", version = 1.0, info = "", logo = "")

public class Chickenkiller extends Script {
@Override
public void onStart() {
log("Let's get started");
}

@Override
public int onLoop() throws InterruptedException {
log("loop works");
NPC npcName = getNpcs().closest(npc -> npc.getName().startsWith("Chicken"));
// Area lumbChicken = new Area(
// new int[][]{
// { 3225, 3301 },
// { 3225, 3301 },
// { 3237, 3301 },
// { 3237, 3301 },
// { 3237, 3293 },
// { 3237, 3293 },
// { 3225, 3293 },
// { 3225, 3293 }
// }
// );
// WebWalkEvent webEvent = new WebWalkEvent(lumbChicken);
attackNPC(npcName);
return 750; //The amount of time in milliseconds before the loop starts over
}
public void attackNPC(NPC enemyName){
if(enemyName.isAttackable() && myPlayer().getInteracting() == null){
enemyName.interact("Attack");
}
}
@Override
public void onExit() {

//Code here will execute after the script ends

}

@Override
public void onPaint(Graphics2D g) {

//This is where you will put your code for paint(s)

}

}
21 hours ago, pooki123 said:

I just dont see what im doing wrong. on google i found the following: "The NullPointerException (NPE) typically occurs when you declare a variable but did not create an object and assign it to the variable before trying to use the contents of the variable. So you have a reference to something that does not actually exist." i dont understand what it means can sombody help?

The method is returning null so npcName doesn't exist. You need to null check stuff like that.

if (npcName != null) {
	// Call stuff
}
  • Author
On 6/26/2023 at 1:08 PM, Gunman said:

The method is returning null so npcName doesn't exist. You need to null check stuff like that.

if (npcName != null) {
	// Call stuff
}

thanks!

 

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.