472,780 Members | 1,144 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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 11875
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: NadaHombre | last post by:
Hello, If I want to make a class which is a stack of objects of some specific type (not just "Objects"), what is the best way to do it? I wonder if there is some generally accepted "best" way to...
0
by: daniel li | last post by:
I got another convert issue. This is the same project as I posted yesterday, and received a perfect response. The conversion threw a SupportClass for me and one of the data type is...
48
by: shana07 | last post by:
Hi again, would like to consult about List problem. //start code java.util.List ifs = new java.util.ArrayList(); // we're in the 'getMonitor' method Instruction insn =...
4
by: puntino | last post by:
Hi I have created my Alarm, at compile time I don't have any problem, but at run time I receive the follo wing messages: Exception in thread "main" java.lang.NullPointerException at...
1
madhoriya22
by: madhoriya22 | last post by:
Hi, My JVM does not support java.util.Scanner class. Is it too new or too old for Scanner class. Currently I am working on jdk1.5.0_04. While using Scanner class java compiler shows this message :-...
4
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at...
6
oll3i
by: oll3i | last post by:
when i run my jsp file i get an error SEVERE: Servlet.service() for servlet jsp threw exception java.util.MissingResourceException: Can't find bundle for base name MessagesBundle, locale pl_PL...
4
by: sukatoa | last post by:
This was my first time to encouter this kind of exception.... that exception appears when i invoked the the method below. private final String encrypting(String enc){ int...
1
by: jimgym1989 | last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException this is my code /** * @(#)textFileRead.java * * * @author * @version 1.00 2008/10/17 */
6
by: monkey0525 | last post by:
Each time I run the ProgTwo program, it displays: 1. Display one product 2. Display all products 3. Add a new CD 6. Exit Enter your choice: Exception in thread "main"...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.