Results 1 to 4 of 4
  1. #1
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default compilation error(version problem?)

    hi i tried the following example
    Java Code:
    import java.util.*;
    
    public class Program
    {
        public static void main(String[] args)
        {
            // Create an ArrayList containing a simple sentence.
            ArrayList arrList = new ArrayList();
            arrList.add(new String("Today"));
            arrList.add(new String("is"));
            arrList.add(new String("Thursday"));
    
            // Change the day to Friday.
            arrList.set(2, new String("Friday"));
    
            Iterator iter = arrList.iterator();
            while (iter.hasNext())
            {
                System.out.print(iter.next() + " ");
            }
        }
    }
    i get this following compilation error

    C:\world>javac Program.java
    Note: Program.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    i use jdk1.5.0_15 is this the problem? i think the problem is using .add() method ...am i wrong?

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default Generics

    Quote Originally Posted by Ms.Ranjan View Post
    i use jdk1.5.0_15 is this the problem? i think the problem is using .add() method ...am i wrong?
    Java Code:
    C:\world>javac Program.java
    Note: Program.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Google for Java Generics.
    Java Code:
    TreeMap<Integer,Object> tm = new TreeMap<Integer,Object>();
    Or something like that.
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default

    Recompile with -Xlint:unchecked for details.
    Have you tried what the compiler recommends? You will get more detailed line-by-line warnings showing where the problems are in your code.
    To remove these warnings, you need to use Generics. They allow the compiler to type check your use of methods that previously took type Object and required the programmer to typecast objects passed into and out of Collection items for example. By using Generics, you won't have to type cast and the compiler will check that your objects are the correct type.

  4. #4
    Ms.Ranjan is offline Member
    Join Date
    Jun 2008
    Posts
    85
    Rep Power
    0

    Default

    Thankyou very much i could solve it by using this...

    Java Code:
    ArrayList<String> arrList = new ArrayList<String>();

Similar Threads

  1. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 08:17 PM
  2. Unresolved compilation problem
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:49 PM
  3. Replies: 1
    Last Post: 08-09-2007, 08:32 PM
  4. compilation error with Jcreator
    By Heather in forum JCreator
    Replies: 2
    Last Post: 06-30-2007, 05:12 PM
  5. compilation issue
    By orchid in forum Eclipse
    Replies: 2
    Last Post: 04-20-2007, 01:51 AM

Posting Permissions

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