469,366 Members | 2,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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.Arrays;
import java.util.Collections;
import java.util.ArrayList;
/**
* @author HP_Owner
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FieldCalculations {

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

public SearchTest()
{
list=new ArrayList<String>(Arrays.asList(colors));
Collections.sort(list);

}

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

}

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

result=Collections.binarySearch(list,key);

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

public static void main(String[] args) {

FieldCalculations calcFields = new FieldCalculations();
calcFields.search();
}
}
Sep 8 '05 #1
4 11650
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
Sep 9 '05 #2

"3rdshiftcoder" <go@away.com> wrote in message
news:h84Ue.2113$0Q2.33@trndny01...
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.


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
Sep 9 '05 #3
http://www.plsgoogleit.com/
"3rdshiftcoder" <go@away.com> wrote in message
news:Xm3Ue.454$Ef2.318@trndny04...
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.Arrays;
import java.util.Collections;
import java.util.ArrayList;
/**
* @author HP_Owner
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class FieldCalculations {

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

public SearchTest()
{
list=new ArrayList<String>(Arrays.asList(colors));
Collections.sort(list);

}

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

}

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

result=Collections.binarySearch(list,key);

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

public static void main(String[] args) {

FieldCalculations calcFields = new FieldCalculations();
calcFields.search();
}
}

Sep 9 '05 #4
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" <xm**@nospam.tv> wrote in message news:df**********@ss405.t-com.hr...
http://www.plsgoogleit.com/

Sep 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by NadaHombre | last post: by
48 posts views Thread by shana07 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.