Reputation: 449
I have netbeans and I added a Gson library with {"classpath" : gson-2.8.0.jar} and {"sources" : gson-2.8.0-sources.jar} and {"javadoc" : gson-2.8.0-javadoc.jar}, as suggested in this post:
Adding Gson to netbeans java project
Now when I create java file below:
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.util.*;
class test{
Map<Integer,Set<Integer>> map = new HashMap<Integer,Set<Integer>>(){
{
put(1,new HashSet<Integer>(){{add(3); add(2);}};
}
};
Gson gson = new Gson();
Type typeOfHashMap = new TypeToken<Map<Integer, Set<Integer>>>() { }.getType();
String jsonMap = gson.toJson(map, Map.class);
}
I seem to have forgetten to include main method but you know what the code means. When I run this I get the following error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: class Type
According to the other post I shoudl have gotten everything I need from that download, but for some reason the Type class wasnt in the files. How do I fix this please I'd appreciate any help.
Upvotes: 2
Views: 2642
Reputation: 3260
Add import statement
import java.lang.reflect.Type;
Its part of java language, not from external libraries.
Try to use automatic import shortcuts. For eclipse (Ctrl + Shift + O). For netbeans I am not sure may be (Ctrl + Shift + I)
Upvotes: 3