Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

unknown error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a Lab problem for a class that I am doing but when I go to compile it I am getting an error that I have no clue what it is. Here is the program

import java.util.*;
public class Lab23A {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(new String("Happy"));
list.add(new String("Sleepy"));
list.add(new String("Sneezy"));
list.add("Doc");
for (int i = 0; i < list.size(); i++) {
System.out.println((String)list.get(1));
}
}
}

The error I get is as followed

Note: Lab23A.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Can someone help please.

Thanks
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Please take time to do a quick google. Its actually quicker than posting! Anyway I guess youe are using J2SE1.5 - Google your error, and if you are still stuck look at generics

Regards

Ramen
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just about any answer to a question can be found using a search engine.

Did you recompile with -Xlint as it tells you to do? The problem does have to do with generics, but it is not an error(unless you have the compiler set to stricter then default). It is a warning, your program should run fine as is.

It is a good idea to take care of it, look up generics to fix it.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Andy, that was "only" a warning, not an error. Four warnings to be precise. At every add(). But your program compiled and will run without an exception.

Try
ArrayList<String> list = new ArrayList<String>();

instead of
ArrayList list = new ArrayList();


and perhaps work through the Sun Tutorial about Generics.


And there is one logical mistake:
System.out.println((String)list.get(1));

Shouldn't it be get(i)?


Yours,
Bu.
 
reply
    Bookmark Topic Watch Topic
  • New Topic