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.

Null pointer with ArrayList?

Featured Replies

Declaring the ArrayList

	public ArrayList<Integer> allTimes;

One function for array:

				if (!allTimes.isEmpty() && allTimes != null) {
					allTimes.clear();
				}

Second function:

							tripE = System.currentTimeMillis() - tripS;
							if (allTimes != null) {
								allTimes.add((int)tripE);
							}

Calculating average times.

		int averageTime = 0;
		if (allTimes.toArray().length > 3) {
			int total = 0;
			for (int i = 0; i < allTimes.toArray().length; i++) {
				total += allTimes.get(i).intValue();
			}
			averageTime = (total / allTimes.toArray().length);
		}

I don't know if it's the only one but the Nullpointer is thrown on allTimes.clear();

Edited by Paradox68

Declaring the ArrayList

	public ArrayList<Integer> allTimes;

One function for array:

				if (!allTimes.isEmpty() && allTimes != null) {
					allTimes.clear();
				}

Second function:

							tripE = System.currentTimeMillis() - tripS;
							if (allTimes != null) {
								allTimes.add((int)tripE);
							}

Calculating average times.

		int averageTime = 0;
		if (allTimes.toArray().length > 3) {
			int total = 0;
			for (int i = 0; i < allTimes.toArray().length; i++) {
				total += allTimes.get(i).intValue();
			}
			averageTime = (total / allTimes.toArray().length);
		}

I don't know if it's the only one but the Nullpointer is thrown on allTimes.clear();

 

should null check before checking if isnt empty

  • Author

should null check before checking if isnt empty

 

 

So the null check works, but why is it throwing a null? Now the code just isn't being called.

Post where the lines you update the allTimes reference. You are assigning it null somewhere

So the null check works, but why is it throwing a null? Now the code just isn't being called.

 

 

You need to initialize the array list. Right now, you are declaring an arraylist but not initializing it.

 

ArrayList blah = new ArrayList

  • Author

Thanks guys, I forgot to post on the thread when I corrected it but Czar was right. I had to assign an initial value of an ArrayList.

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.