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 8815411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:22:12+00:00 2026-06-14T04:22:12+00:00

I have a problem with the application I’m trying to develop. It’s a music

  • 0

I have a problem with the application I’m trying to develop.
It’s a music game for Android, I obtain all the data from iTunes.

This is the part where i get the data. I have 2 lists:

  1. List canzoni: size 5, fields: previewUrl, artistName, trackName, artistViewUrl and artworkUrl100.
  2. List dieciCanzoni: size 10, must contain 10 elements of the above list.

This is the code that fills the lists:

try
    {       
        int randomLookupId;
        JSONObject obj = getJSONObject(url);                            
        JSONArray jsonArray = obj.getJSONArray("resultIds");            

        for(int i = 0; i < 10; i++)
        {
            canzoni.clear();

            randomLookupId = new Random().nextInt(jsonArray.length());  

            JSONObject finalObj = getJSONObject("http://itunes.apple.com/lookup?id="+jsonArray.getString(randomLookupId)); 
            JSONArray finalJsonArray = finalObj.getJSONArray("results");    

            JSONObject returnObj = finalJsonArray.getJSONObject(0);

            canzoni.add(returnObj.getString("previewUrl"));
            canzoni.add(returnObj.getString("artistName"));
            canzoni.add(returnObj.getString("trackName"));
            canzoni.add(returnObj.getString("artistViewUrl"));
            canzoni.add(returnObj.getString("artworkUrl100"));

            Canzone.dieciCanzoni.add(i, canzoni);

        }
    }   
    catch (JSONException ignored)
    {
        ignored.getCause();
    }
    catch (MalformedURLException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

The retrieval of informations works very well, I have only one problem: when I clear the list canzoni, I noticed that the list dieciCanzoni has been cleared too, and obviously I don’t want that!

And if I comment the line that clear the canzoni list, in the dieciCanzoni list is inserted only the last values in canzoni, even the previously inserted values change!

Can you help me please figuring it out?

Thank you all!

  • 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-14T04:22:14+00:00Added an answer on June 14, 2026 at 4:22 am

    You need to use a deep copy:

    Canzone.dieciCanzoni.add(i, canzoni.clone());
    

    or:

    Canzone.dieciCanzoni.add(i, newArrayList<String>(canzoni));
    

    What’s happening is Canzone.dieciCanzoni.add(i, canzoni); only points to the same location where the information is stored. When you clear either list you are clearing the one location for both of them. A “deep copy” duplicates the data so each list has it’s own copy.


    Better yet, don’t use clear(). Simply create a new list for canzoni from the start. Replace:

    canzoni.clear();
    

    with:

    canzoni = new ArrayList<String>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with running an android application from eclipse on real android device
I have a problem with my application. First of all on a previous page
I have problem with my Android application. I need an application that will send
I have following problem: My webservice application returns xml data in following order: <my_claims>
i have problem using camera in my Android application i have a form for
I have a problem with an application I'm currently developing. In this program I
I have problem with callbacks from other application thread. Dll is some kind of
i have problem on C# console application. i declare : DataTable MasterExcel = this
I have this problem in my application: Step 1 - create an file (xml)
I have problem running a Java RCP application via Java Webstart. This works for

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.