Error about Source Level only if 5.0? I'm using Java 1.6? Maps
Hello everyone. I was just trying to run some simple Source Code from my book here:
package mapa;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
publicclass MapTest
{
Map<String, String> phonebook =new HashMap<String, String>();
// constructor
public example2(String n[], String nums[]){
for(int i=0; i< n.length; i++)
phonebook.put( n[i], nums[i] );
}
publicstaticvoid main(String[] args){
// data
String [] names ={"Lefty","Guarav","Wong","Rupamay"};
String [] extns ={"4873","4810","3769","0"};
// get an instance of this class
example2 ex =new example2( names, extns );
// dump out the map
System.out.println("map: " + ex.phonebook);
// get the mappings
Set<Map.Entry><String,String>> s = ex.phonebook.entrySet();
// iterate over the mappings
//for (Iterator i = s.iterator(); i.hasNext(); ) {
for (Map.Entry me : s){
Object ok = me.getKey();
Object ov = me.getValue();
System.out.print("key=" + ok );
System.out.println(", value=" + ov );
}
}
}
and i'm getting the following errors when I run it in Eclipse:
Exception in thread"main" java.lang.Error: Unresolved compilation problems:
example2 cannot be resolved to a type
example2 cannot be resolved to a type
Syntax error, parameterized types are only availableif source level is 5.0
The type Map.Entry is not generic; it cannot be parameterized with arguments <String, String>
Syntax error,'for each' statements are only availableif source level is 5.0
at mapa.MapTest.main(MapTest.java:24)
Line 24 is:
example2 ex =new example2( names, extns );
I've compiled things with Eclipse before such as Networking programs and they worked fine, not sure whats wrong with this example.
Thanks!

