Results 1 to 8 of 8
  1. #1
    daydreamer is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default Iterator next import class?

    Hi.

    I am creating a java applet, but I dont think I am importing the correct classes:


    Java Code:
    import java.applet.*;
    import java.io.*;
    import java.net.*;
    import java.awt.event.*;
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import java.util.*;
    import java.util.ListIterator;
    import java.util.List;
    
    
                       Map<String, List<String>> headers = connection.getHeaderFields();
                        List<String> values = headers.get("Set-Cookie");
    
                        String cookieValue = null;
                        for (Iterator iter = values.iterator(); iter.hasNext(); ) {
                             String v = values.next();
                             if (cookieValue == null)
                                 cookieValue = v;
                             else
                                 cookieValue = cookieValue + ";" + v;
                        }
    error:

    httpc.java:180: cannot find symbol
    symbol : method next()
    location: interface java.util.List<java.lang.String>
    String v = values.next();



    Which class am I missing? thanks.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    values is a List<String> and lists don't have a next(). (Thst's the significance of the "symbol" and "location" parts of the error message.)

    Iterators have a next(), so call next on the iterator instance.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,300
    Rep Power
    20

  4. #4
    daydreamer is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

    Fixed the error with:

    Java Code:
                        String cookieValue = null;
                        for (Iterator iter = values.iterator(); iter.hasNext(); ) {
                             String v = iter.next().toString();
                             if (cookieValue == null)
                                 cookieValue = v;
                             else
                                 cookieValue = cookieValue + ";" + v;
                        }
    I assumed the code would work because it was directly taken from Cookie Support.

    Yes I did cross post - I want sure which of the two forums were responsive.

    Thanks for the help, much appreciated

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

    Default

    Quote Originally Posted by daydreamer View Post
    Yes I did cross post - I want sure which of the two forums were responsive.
    Do this a lot without letting us know that you're doing it, and you'll make sure that no forum will respond to you. No one wants to spend time helping someone only to find out that the solution was posted hours before elsewhere. The proper thing is that if you do this, please be upfront about it and post links. Thanks for your cooperation.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    I'm glad you fixed the error. (and I agree with Fubarable about the need to be upfront - so that everyone can follow all of the discussion). Did you understand what I said about interpreting the "symbol not found" message? You've fixed the error, but that message is one you may well see again!

  7. #7
    daydreamer is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default

    Yeh I understand the concepts I think...

    so a List<String> is similar to an array.

    Java Code:
    Iterator iter = values.iterator();
    creates an Iterator object needed to iterate the list.

    the values.next(); method does not exist for List<String>, it will only work if you create an Iterator object from a List<String>.


    Is that correct?

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Yes. Although I was also thinking along the lines of "cannot find symbol" meaning "that method doesn't exist!". Common reasons are typos, and - as in this case - calling the right method, but on the wrong instance.

Similar Threads

  1. import class
    By Dipke in forum New To Java
    Replies: 5
    Last Post: 08-09-2010, 10:54 AM
  2. Replies: 0
    Last Post: 05-18-2010, 12:53 AM
  3. how to Import my Java Class in Jsp Page
    By pos in forum JavaServer Pages (JSP) and JSTL
    Replies: 20
    Last Post: 04-06-2010, 02:51 PM
  4. can't import my own class
    By Splat in forum New To Java
    Replies: 5
    Last Post: 10-13-2009, 04:53 AM
  5. Replies: 4
    Last Post: 12-29-2008, 02:20 PM

Posting Permissions

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