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.

how to use an arraylist.

Featured Replies

Hello forums, just a note before i start, i try to look up the answers for my questions on google before i come here to ask, and ive been trying for hours to get this to work to no avial. anyways, i have an arrayList of strings for a loot list (or atleast i think i do, every time i try to log the contents i just get a null pointer). anyways. im trying to turn the arraylist into an array so i can use it to find the closest ground item. 

here is my current function to determine if i should loot a stackable item. 

 

 
the arraylist is transfered from an arraylist from the gui using this.(which is called in onStart() )
 
 if(gui.UseLooting)
       {
    log("setting looting shit");
    UseLooting = true;
       
    LootListStackable = gui.StackableLootList;
       
    LootListNotStackable = gui.NonStackableLootList;
    log("DISPLAYING LISTS");
   // log(gui.StackableLootList.size());
    //log(LootListStackable.size()); commented out because they both caused null pointers
       }
 
the arraylists are declared in the gui like so
 
public ArrayList<String>  StackableLootList;
 
and contents are added to the list in the gui when a button is pushed like so
 
 StackableLootList.add(LootToAdd.getText());
 
i literally have no idea why i get a null pointer whenever i try to do anything with the array lists in my main code. please help sad.png
 
 
 

 

Edited by roguehippo

Post all of the relevant code so I can see your problem, and Ill answer everything in one reply.

Plz indent it properly as well, ty.

Make sure that when you declare the list you instantiate it, i.e.

public ArrayList<String> StackableLootList = new ArrayList<>();

.NET conventions in Java :/ ..

 

Anyway, we need to see whats going on in the gui class to identify the problem

  • Author

Post all of the relevant code so I can see your problem, and Ill answer everything in one reply.

Plz indent it properly as well, ty.

 

here is the code for my gui. 

 

http://pastebin.com/HUNyAuFY

 

the adding of the strings when the loot button is pressed is at line 281.

 

here is my main code. 

 

http://pastebin.com/HsuELXZi

 

the looting functions are at the bottom

 

thanks :)

here is the code for my gui. 

 

http://pastebin.com/HUNyAuFY

 

the adding of the strings when the loot button is pressed is at line 281.

 

here is my main code. 

 

http://pastebin.com/HsuELXZi

 

the looting functions are at the bottom

 

thanks smile.png

 

public ArrayList<String>  StackableLootList;
public ArrayList<String>  NonStackableLootList;
 
Should be
 
public ArrayList<String>  StackableLootList = new ArrayList<>();
public ArrayList<String>  NonStackableLootList = new ArrayList<>();

String[] lootArray = new String[stackableLootList.size()];

 

StackableLootList.toArray(lootArray);

  • Author

 

public ArrayList<String>  StackableLootList;
public ArrayList<String>  NonStackableLootList;
 
Should be
 
public ArrayList<String>  StackableLootList = new ArrayList<>();
public ArrayList<String>  NonStackableLootList = new ArrayList<>();

 

thanks so much for getting back to me :) i didnt know that initializing it in this specific way was necesarry or even made a difference. is it easy to explain why this makes a difference? (i just want to make my future coding as good as possible)

thanks so much for getting back to me smile.png i didnt know that initializing it in this specific way was necesarry or even made a difference. is it easy to explain why this makes a difference? (i just want to make my future coding as good as possible)

If you don't initialize a variable before you use it, it will return as null. There are some exceptions such as int, long etc.

  • Author

i guess something else is wrong because im still getting null pointers when i do anything with the grounditem

i guess something else is wrong because im still getting null pointers when i do anything with the grounditem

 

Just implement enough checks to see if the GroundItems are null? Just check out your logs there would be the exact line the program is throwing a NullPointer.

i guess something else is wrong because im still getting null pointers when i do anything with the grounditem

You have to define and do a null check before using it

  • Author

Im posting here just so anyone else that has this problem can hopefully find the answer. After looking on many forums i found out the problem was actually due to an import mistake. i accidently imported like java.awt.List instead of java.util.List. -___-

Im posting here just so anyone else that has this problem can hopefully find the answer. After looking on many forums i found out the problem was actually due to an import mistake. i accidently imported like java.awt.List instead of java.util.List. -___-

classic beginner mistake :boge:

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.