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

  • SEARCH
  • Home
  • 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 8408999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:47:12+00:00 2026-06-09T23:47:12+00:00

I’m new to Android and Java but do have some experience in Objective C

  • 0

I’m new to Android and Java but do have some experience in Objective C and iPhone programming. I’m attempting to recreate an app I’ve already designed for the iPhone and am getting stuck on what should be a simple concept.

In my ParserHandler class I am parsing an XML from a server and putting the data into three separate ArrayList’s. The parsing appears to be working fine. When I log and iterate through the ArrayList within my ParserHandler.java class it all works fine.
(List1.java class has a few string variables and I’ve declared it like so in the ParserHandler: private List1 theList = new List1(); )

for(int i = 0; i<dogArray.size(); i++){
        theList = dogArray.get(i);
        Log.i(TAG, "looping " + i + " " + theList.Name);
        Log.i(TAG, "looping " + i + " " + theList.PhotoUrl);
        Log.i(TAG, "looping " + i + " " + theList.Type);


        }//this loops fine and has all the data

The dogArray is declared like so: public ArrayList<List1> dogArray = new ArrayList<List1>();
Now I want to access the dogArray from the class DogListView.java so in the onCreate method I attempt to do the following:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dog_list_view);
        ParserHandler ph = new ParserHandler();
        int d = ph.getNumberofDogs();
        int m = ph.dogArray.size();
        Log.i(TAG, "dog size is:" + d + "and:" + m);}

I’ve tried two different ways and both always return “0” in the log. However the correct size is always logged and all the data is there when the log comes from the ParserHandler.java class.

This is the accessor method in ParserHandler.java.

   public int getNumberofDogs(){
            return dogArray.size();
        }

I’d prefer to access the dogArray via accessor method (as this seems to be best practice from what I’ve gathered) however I’m open to all suggestions.

Thanks in advance!!

EDIT 8/23/12

I ended up solving the problem by declaring my ArrayLists Static. I know this (and public) approach my not be ideal for OOP but i’m going with it. In my ParserHandler.java I declared

public static ArrayList<List1> dogArray = null; 
public static ArrayList<List1> otherArray = null;
public static ArrayList<List1> catArray = null;

Then begin my SAX parser:

@Override
    public void startElement(String uri, String localName, String qName,
            Attributes attributes) throws SAXException {
        // TODO Auto-generated method stub
        super.startElement(uri, localName, qName, attributes);
        if (qName.equalsIgnoreCase("ArrayOfDataFeedAnimal")){
            catArray = new ArrayList<List1>();
            dogArray = new ArrayList<List1>();
            otherArray = new ArrayList<List1>();
        }else if(qName.equalsIgnoreCase("DataFeedAnimal")){
            theList = new List1();
        }

then the rest of my SAX parsing stuff happens. Lastly, from whatever class I want to access the array i simply do that in the static way by ParserHandler.dogArray.size() to get the size of the array. I can now manipulate the array any way i see fit from whatever class i need to get it.

I’m still unclear why creating an instance of the ParserHandler class hasn’t worked for me with my parsed ArrayLists because when it worked fine when I tested with a simple int[].

hopefully this can help someone else in the future.

Thanks again for everyones feedback!

Cheers!

  • 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-06-09T23:47:13+00:00Added an answer on June 9, 2026 at 11:47 pm

    you can do it in two ways,

    1. Create a setter/getter class
    2. Make a public static method that returns ArrayList

    First Method:

    class name : myDataObject.java

    private ArrayList myArrayList;
    
    // setting the ArrayList Value 
    public void setArrayList ( ArrayList myArrayList )
    {
         this.myArrayList = myArrayList;
    }
    
    // getting the ArrayList value 
    public ArrayList getArrayList() 
    {
         return myArrayList;
    }
    

    Second Method:

    In ArrayList file, ( suppose class name is class A.java )

    private static ArrayList myArrayList = null; 
    
    ... 
    // assign arraylist 
    
    public static ArrayList getArrayList()
    {
          return myArrayList;
    }
    

    in the calling activity/class you can call it using following code,

    private ArrayList newArrayList = null;
    
    newArrayList = A.getArrayList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.