Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Eclipse not compiling my Java file

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-07-2010
Member
 
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.

Reply With Quote
  #2  
Old 25-07-2010
Member
 
Join Date: Dec 2008
Posts: 183
Re: Eclipse not compiling my Java file

Quote:
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.!!
Reply With Quote
  #3  
Old 25-07-2010
Member
 
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.
Reply With Quote
  #4  
Old 25-07-2010
Member
 
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?
Reply With Quote
  #5  
Old 25-07-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Eclipse not compiling my Java file"
Thread Thread Starter Forum Replies Last Post
getting error while connecting Eclipse with java mbangali Windows Software 3 15-09-2011 09:56 PM
Java Card 2.1.1 Plugin for Eclipse Marjorie Software Development 5 23-07-2010 01:40 AM
Install Eclipse for Java and Android blueprats Guides & Tutorials 4 10-03-2010 02:20 PM
Getting an Error while Compiling the Java program Rob Dizzle Software Development 4 18-01-2010 10:24 PM
Eclipse for your Java applications JamesMK Guides & Tutorials 3 22-06-2009 03:44 PM


All times are GMT +5.5. The time now is 03:17 AM.