Hello every body:
I used java 1.5 ;
there is something wrong in the last line; //////////////////////////////////////////////////////////
import java.util.HashMap;
import java.util.Map;public class TestMap {
public static void main(String args[]) {
args[0] = "a";
args[1] = "hello";
Map<String,Integer> map = new HashMap<String,Integer>();
for (int i = 0; i < args.length; i++) {
map.put(args[i], i);
}
Integer position = map.get("hello"); // here something wrong: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
}
}Who can help me?
Thank you!
I used java 1.5 ;
there is something wrong in the last line; //////////////////////////////////////////////////////////
import java.util.HashMap;
import java.util.Map;public class TestMap {
public static void main(String args[]) {
args[0] = "a";
args[1] = "hello";
Map<String,Integer> map = new HashMap<String,Integer>();
for (int i = 0; i < args.length; i++) {
map.put(args[i], i);
}
Integer position = map.get("hello"); // here something wrong: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
}
}Who can help me?
Thank you!
My eclipse version is 3.2,but it doesn't work!!!
no problem!
args[0] = "a ";
args[1] = "hello ";
这个作为main的传入参数,怎么能随便改呢,会不会报异常呢?
试了,报
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at generic.TestMap.main(TestMap.java:8)
public class TestMap {
public static void main(String args[]) {
String teststring[]=new String[2];
teststring[0] = "a";
teststring[1] = "hello ";
Map<String, Integer> map = new HashMap<String, Integer>();
for (int i = 0; i < teststring.length; i++) {
map.put(teststring[i], i);
}
Integer position = map.get("hello "); // here something wrong: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
System.out.print(position);
}
}