Results 1 to 5 of 5

Thread: Eclipse not compiling my Java file

  1. #1
    Join Date
    Jan 2010
    Posts
    56

    Eclipse not compiling my Java file

    Can anyone tell me why my eclipse so with the experiment to compile my code..?? I always get this message :
    Code:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The type ArrayList is not generic; it cannot be parameterized with arguments <Integer> 
    Syntax error, parameterized types are only available if source level is 5.0 
    The type ArrayList is not generic; it cannot be parameterized with arguments <Integer> 
    Syntax error, parameterized types are only available if source level is 5.0
    I am hoping that some members over there should be knowing some solutions for this.!! Please help me as soon as possible.

  2. #2
    Join Date
    Dec 2008
    Posts
    183

    Re: Eclipse not compiling my Java file

    The type ArrayList is not generic, it can not be parameterized with arguments <Integer>
    Syntax error, parameterized types are only available if source level is 5.0
    You should still uses Java 1.4, but according to the task and, above all, for your own well-being on Java 1.5 upgrade. I am sure that updating your application will definitely help you.!!

  3. #3
    Join Date
    Dec 2008
    Posts
    202

    Re: Eclipse not compiling my Java file

    In Java 1.4, there is only untyped lists: one can poke objects of any type and must at always cast to the desired type "," where a lot of funny mistakes can occur, if not all objects in the list of the same type. So even I would like to recommend you to update your Java application. If you want some more help regarding the Eclipse for your Java Application, you can see here.

  4. #4
    Join Date
    Jan 2006
    Posts
    211

    Re: Eclipse not compiling my Java file

    You can check the following example :
    Code:
    List strings = new LinkedList(); 
    strings.add("Lama");
    strings.add("Duck");
    strings.add(new Integer(0xCAFE));
    
    Iterator it = strings.iterator(); 
    while(it.hasNext()) { 
    String animal = (String)it.next(); 
    System.out.println(animal); 
    }
    The above code will compile correctly, the duration of the loop but in a ClassCastException thrown when it.next () instead of the string-awaited returns the integer, which we have inserted last in the list. Would not it be nice if you could tell the compiler that should only contain a list of objects of a certain type, so that such errors are detected already during programming?

  5. #5
    Join Date
    Jan 2009
    Posts
    140

    Re: Eclipse not compiling my Java file

    I would like to comment on coding given by the "PARRISH". The same code can be much more concisely written and type-safe, especially if you Generics, uses a new feature in Java 1.5. This can already be set at compile time, which types are allowed in a list, that is, the compiler will not allow inserting invalid types (known as "parameterized types"):
    Code:
    List<String> strings = new LinkedList<String>();
    strings.add("Lama"); // ok 
    strings.add("Duck"); // ok 
    strings.add(new Integer(0xCAFE));
    
    for(String animal : strings) 
    { 
    Element in the list "strings" 
    System.out.println(animal); 
    }
    The above code will not compile because of the attempt to insert an integer in the list, but you can at runtime be 100% sure that the list really just strings. The loop is also freed from Typcasts and can be transferred to another new 1.5 feature (enhanced for) written more elegant without iterator.

Similar Threads

  1. getting error while connecting Eclipse with java
    By mbangali in forum Windows Software
    Replies: 3
    Last Post: 15-09-2011, 09:56 PM
  2. Java Card 2.1.1 Plugin for Eclipse
    By Marjorie in forum Software Development
    Replies: 5
    Last Post: 23-07-2010, 01:40 AM
  3. Install Eclipse for Java and Android
    By blueprats in forum Guides & Tutorials
    Replies: 4
    Last Post: 10-03-2010, 02:20 PM
  4. Getting an Error while Compiling the Java program
    By Rob Dizzle in forum Software Development
    Replies: 4
    Last Post: 18-01-2010, 10:24 PM
  5. Eclipse for your Java applications
    By JamesMK in forum Guides & Tutorials
    Replies: 3
    Last Post: 22-06-2009, 03:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,907,562.46370 seconds with 17 queries