Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:48:35+00:00 2026-05-31T00:48:35+00:00

In my processing program, I added an object into a global ArrayList called items

  • 0

In my processing program, I added an object into a global ArrayList called items in my draw function.

Here is the class.

class Obj {
    String name;
    Obj(String name) {
        self.name = name;
    }
}

Here is my draw function.

void draw () {
    items.add(new Obj("Bob"));
}

I tried printing the size of items in my mouseClicked() function into the console, but I keep getting 0.

void mouseClicked () {
    print(items.size());
} 

Why?

The ArrayList is declared at the top of my file after my class:

ArrayList<Obj> items = new ArrayList<Obj>();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:48:36+00:00Added an answer on May 31, 2026 at 12:48 am

    There are a couple of things which aren’t quite there yet:

    1. self.name = name; should be this.name = name;
    2. You’re creating tons of objects (based on framerate), but only checking the size of the array in mouseCliked() (also you might want to use println() instead).

    Try this:

    ArrayList<Obj> items = new ArrayList<Obj>();
    
    void setup(){
    
    }
    void draw () {
    
    }
    void mouseClicked () {
      items.add(new Obj("Bob"));
      println("items size: " + items.size());
    } 
    class Obj {
        String name;
        Obj(String name) {
            this.name = name;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my Processing program that I'm editing in Eclipse: import processing.core.PApplet; @SuppressWarnings(serial) public
I'm writing an image processing program to perform real time processing of video frames.
I've written an image processing program in MATLAB which makes heavy use of the
I'm trying to write a very simple image processing program for fun and practice.
I have created a concurrent, recursive directory traversal and file processing program, which sometimes
after some processing my program shows a messagebox saying you can read a log
I'm in the processing of converting a program from Perl to Java. I have
I am trying to add some post-processing capabilities to a program. The rendering is
I am making an application that does some custom image processing. The program will
I have written a mail-processing program, which basically slaps a template on incoming mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.