1
resposta

Erro no Eclipse com Gson

Alguém pode me ajudar?

Eu fiz o exercício adicionando a biblioteca no Eclipse e aparece os seguintes erros:

Digite um filme para busca: 
dogville
{"Title":"Dogville","Year":"2003","Rated":"R","Released":"23 Apr 2004","Runtime":"178 min","Genre":"Crime, Drama","Director":"Lars von Trier","Writer":"Lars von Trier","Actors":"Nicole Kidman, Paul Bettany, Lauren Bacall","Plot":"A woman on the run from the mob is reluctantly accepted in a small Colorado community in exchange for labor, but when a search visits the town she finds out that their support has a price.","Language":"English","Country":"Denmark, Netherlands, Sweden, Germany, United Kingdom, France, Finland, Norway, Italy","Awards":"21 wins & 33 nominations","Poster":"https://m.media-amazon.com/images/M/MV5BMTkwNTg2MTI1NF5BMl5BanBnXkFtZTcwMDM1MzUyMQ@@._V1_SX300.jpg","Ratings":[{"Source":"Internet Movie Database","Value":"8.0/10"},{"Source":"Rotten Tomatoes","Value":"69%"},{"Source":"Metacritic","Value":"61/100"}],"Metascore":"61","imdbRating":"8.0","imdbVotes":"153,668","imdbID":"tt0276919","Type":"movie","DVD":"01 Jun 2007","BoxOffice":"$1,535,286","Production":"N/A","Website":"N/A","Response":"True"}
{"Title":"Dogville","Year":"2003","Rated":"R","Released":"23 Apr 2004","Runtime":"178 min","Genre":"Crime, Drama","Director":"Lars von Trier","Writer":"Lars von Trier","Actors":"Nicole Kidman, Paul Bettany, Lauren Bacall","Plot":"A woman on the run from the mob is reluctantly accepted in a small Colorado community in exchange for labor, but when a search visits the town she finds out that their support has a price.","Language":"English","Country":"Denmark, Netherlands, Sweden, Germany, United Kingdom, France, Finland, Norway, Italy","Awards":"21 wins & 33 nominations","Poster":"https://m.media-amazon.com/images/M/MV5BMTkwNTg2MTI1NF5BMl5BanBnXkFtZTcwMDM1MzUyMQ@@._V1_SX300.jpg","Ratings":[{"Source":"Internet Movie Database","Value":"8.0/10"},{"Source":"Rotten Tomatoes","Value":"69%"},{"Source":"Metacritic","Value":"61/100"}],"Metascore":"61","imdbRating":"8.0","imdbVotes":"153,668","imdbID":"tt0276919","Type":"movie","DVD":"01 Jun 2007","BoxOffice":"$1,535,286","Production":"N/A","Website":"N/A","Response":"True"}
Exception in thread "main" com.google.gson.JsonIOException: Failed making field 'ModelosScreenmatch.Titulo#nome' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type.
    at com.google.gson@2.10.1/com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:38)
    at com.google.gson@2.10.1/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:286)
    at com.google.gson@2.10.1/com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:130)
    at com.google.gson@2.10.1/com.google.gson.Gson.getAdapter(Gson.java:556)
    at com.google.gson@2.10.1/com.google.gson.Gson.fromJson(Gson.java:1226)
    at com.google.gson@2.10.1/com.google.gson.Gson.fromJson(Gson.java:1137)
    at com.google.gson@2.10.1/com.google.gson.Gson.fromJson(Gson.java:1047)
    at com.google.gson@2.10.1/com.google.gson.Gson.fromJson(Gson.java:982)
    at CatalogoScreenmatch/Screenmatch.PrincipalComBusca.main(PrincipalComBusca.java:36)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.String ModelosScreenmatch.Titulo.nome accessible: module CatalogoScreenmatch does not "opens ModelosScreenmatch" to module com.google.gson
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
    at com.google.gson@2.10.1/com.google.gson.internal.reflect.ReflectionHelper.makeAccessible(ReflectionHelper.java:35)
    ... 8 more
1 resposta

Natalha, bom dia.

Pelo que olhei pelos logs de erros, na sua classe Titulo no atributo nome ele não está podendo acessar (não está conseguindo ficar acessivel) a sugestão que o erro da e para você aumentar a sua visibilidade do atributo ou escrever um TypeAdapter,.