java.util.list compiler error-beginner

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 3rdshiftcoder

    #1

    java.util.list compiler error-beginner

    Hi-

    I'd like to use this class from a book but am getting a compiler error.
    On the line
    private List < String > list; p.932 Chapter 19
    found in the code below in the eclipse editor it is underlined
    in red. It is saying it is a syntax error and to delete the tokens.

    I'd like to use the code below in my program i am working on for my hobby.
    It will make life so much easier when i get past the compiler error.

    thanks for any help,
    jim


    package calcpackage;
    import java.util.List;
    import java.util.Array s;
    import java.util.Colle ctions;
    import java.util.Array List;
    /**
    * @author HP_Owner
    *
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    */
    public class FieldCalculatio ns {

    private static final String colors[]={"red","green" ,"blue"};
    private List < String > list; // *************** compiler generates error on
    this line*********

    public SearchTest()
    {
    list=new ArrayList<Strin g>(Arrays.asLis t(colors));
    Collections.sor t(list);

    }

    private void search()
    {
    getIndex("green ");

    }

    private int getIndex(String key)
    {
    int result=0;

    result=Collecti ons.binarySearc h(list,key);

    if(result >=0)
    return result;
    else
    System.out.prin tln("error not found "+ result);


    }

    public static void main(String[] args) {

    FieldCalculatio ns calcFields = new FieldCalculatio ns();
    calcFields.sear ch();
    }
    }


  • 3rdshiftcoder

    #2
    Re: java.util.list compiler error-beginner SOLVED

    something wasnt right with my ArrayList or generics maybe?
    anyways http://www.onjava.com/pub/a/onjava/2.../generics.html
    gives an example for jdk 1.4 that is working for me.

    so thanks for any help given.

    have a great end of the week.

    later


    Comment

    • Oliver Wong

      #3
      Re: java.util.list compiler error-beginner SOLVED


      "3rdshiftco der" <go@away.com> wrote in message
      news:h84Ue.2113 $0Q2.33@trndny0 1...[color=blue]
      > something wasnt right with my ArrayList or generics maybe?
      > anyways http://www.onjava.com/pub/a/onjava/2.../generics.html
      > gives an example for jdk 1.4 that is working for me.[/color]

      Generics was introduced in JDK 1.5. If you're using 1.4, your compiler
      won't know what generics are and treat it as a compile time error.

      Check if you can configure Eclipse to use "1.5 compliance" mode instead
      of "1.4 compliance". If no such option exists, it might be time to upgrade
      your Eclipse.

      - Oliver


      Comment

      • xman

        #4
        Re: java.util.list compiler error-beginner




        "3rdshiftco der" <go@away.com> wrote in message
        news:Xm3Ue.454$ Ef2.318@trndny0 4...[color=blue]
        > Hi-
        >
        > I'd like to use this class from a book but am getting a compiler error.
        > On the line
        > private List < String > list; p.932 Chapter 19
        > found in the code below in the eclipse editor it is underlined
        > in red. It is saying it is a syntax error and to delete the tokens.
        >
        > I'd like to use the code below in my program i am working on for my hobby.
        > It will make life so much easier when i get past the compiler error.
        >
        > thanks for any help,
        > jim
        >
        >
        > package calcpackage;
        > import java.util.List;
        > import java.util.Array s;
        > import java.util.Colle ctions;
        > import java.util.Array List;
        > /**
        > * @author HP_Owner
        > *
        > * TODO To change the template for this generated type comment go to
        > * Window - Preferences - Java - Code Style - Code Templates
        > */
        > public class FieldCalculatio ns {
        >
        > private static final String colors[]={"red","green" ,"blue"};
        > private List < String > list; // *************** compiler generates error
        > on this line*********
        >
        > public SearchTest()
        > {
        > list=new ArrayList<Strin g>(Arrays.asLis t(colors));
        > Collections.sor t(list);
        >
        > }
        >
        > private void search()
        > {
        > getIndex("green ");
        >
        > }
        >
        > private int getIndex(String key)
        > {
        > int result=0;
        >
        > result=Collecti ons.binarySearc h(list,key);
        >
        > if(result >=0)
        > return result;
        > else
        > System.out.prin tln("error not found "+ result);
        >
        >
        > }
        >
        > public static void main(String[] args) {
        >
        > FieldCalculatio ns calcFields = new FieldCalculatio ns();
        > calcFields.sear ch();
        > }
        > }
        >
        >[/color]


        Comment

        • 3rdshiftcoder

          #5
          Re: java.util.list compiler error-beginner

          thanks Oliver.


          i have a new java text so i will change to 1.5.
          i wasnt aware of that setting in eclipse.
          i didnt realize it had anything to do with a compiler.
          i thought it was something in my code i wasn't seeing.

          btw i did google and yahoo (for what it's worth).





          "xman" <xman@nospam.tv > wrote in message news:dft0h5$r6g $1@ss405.t-com.hr...[color=blue]
          > http://www.plsgoogleit.com/
          >[/color]


          Comment

          Working...