Results 1 to 4 of 4
  1. #1
    victoryo is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Get the data from arraylist

    Iam trieing to save the data from my arraylist to a file.

    When the file is saved this is in it:

    naam1
    naam2
    model.Turn@6cd5cc1f
    model.Turn@484c3f0b
    model.Turn@5bf1042
    model.Turn@42c46000
    model.Turn@6a7ac23e

    So it doesn't work proper.

    this is my save code:

    Java Code:
            private void saveLeg(File file)
            {
                FileIO legFile = new FileIO(file);
                Leg legread = returnLeg();
                String player1 = legread.getNameP1();
                String player2 = legread.getNameP2();
                ArrayList turn1 = legread.getTurns(1);
                ArrayList turn2 = legread.getTurns(2);
                legFile.save(player1, player2, turn1, turn2, file);
            }
    Java Code:
        public void save(String player1, String player2, ArrayList<Turn> turnsPlayer1, ArrayList<Turn> turnsPlayer2, File f)
    {
    /*     */     try
    /*     */     {
    /* 128 */       if (!f.getName().endsWith(".leg"))
    /*     */       {
    /* 130 */         f = new File(f.getAbsolutePath() + ".leg");
    /*     */       }
    /*     */ 
    /* 135 */       FileWriter fw = new FileWriter(f, false);
    /* 136 */       BufferedWriter bw = new BufferedWriter(fw);
    /* 137 */       String s = "";
    /* 138 */       int Size = turnsPlayer1.size() + turnsPlayer2.size();
    /* 139 */       int p = 0;
    /* 140 */       for(int i = 0; i < Size;)
    /*     */       {
    /* 143 */         s = s + "\r\n" + ((Turn)turnsPlayer1.get(p)).toString();
                      System.out.println(s);
    /* 144 */         i++;
    /*     */ 
    /* 146 */         if (i < Size) {
    /* 147 */           s = s + "\r\n" + ((Turn)turnsPlayer2.get(p)).toString();
    /* 148 */           System.out.println(s);
                        i++;
    /*     */         }
    /*     */ 
    /* 152 */         p++;
    /*     */       }
    /* 154 */       bw.write(player1 + "\r\n" + player2 + s);
    /* 155 */       bw.close();
    /*     */     }
    /*     */     catch (IOException ex) {
    /* 158 */       Message.error("Fout! " + ex);
    /*     */     }
    /*     */   }
    /*     */ }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Get the data from arraylist

    Looks like you need to give one more more classes (I think in particular your Turn class) a decent toString() representation since what y9ou're seeing is a default toString() result, one obtained when you don't properly override this method.

  3. #3
    victoryo is offline Member
    Join Date
    Dec 2011
    Posts
    16
    Rep Power
    0

    Default Re: Get the data from arraylist

    Thanks for your reply! Got it working indeed. forgto to create a toString().

    You are the man! =D

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Get the data from arraylist

    You are welcome. Glad you've got it working!

Similar Threads

  1. Finding the data in Arraylist
    By nickliutw in forum New To Java
    Replies: 29
    Last Post: 09-08-2011, 04:05 PM
  2. Multiplying specific data within a arraylist
    By fiefa in forum New To Java
    Replies: 6
    Last Post: 02-01-2011, 08:54 AM
  3. Load data from file to ArrayList
    By humbug in forum New To Java
    Replies: 3
    Last Post: 01-05-2011, 11:53 AM
  4. Replies: 3
    Last Post: 03-28-2009, 05:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •