Fiz o exercício como a instrutora fez, mas não imprime, aparece essa exception. Por que??
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder at br.com.screenmatch.principal.PrincipalComBusca.main(PrincipalComBusca.java:36) Caused by: java.lang.ClassNotFoundException: com.google.gson.GsonBuilder at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ... 1 more
package br.com.screenmatch.principal;
import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.Scanner;
import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder;
import br.com.screenmatch.modelos.Titulo; import br.com.screenmatch.modelos.TituloOmdb;
public class PrincipalComBusca {
public static void main(String[] args) throws IOException, InterruptedException {
Scanner leitura = new Scanner(System.in);
System.out.println("Digite um filme: ");
String busca = leitura.nextLine();
String endereco = "http://www.omdbapi.com/?t=" + busca + "&apikey=b560d051";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(endereco)).build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
String json = response.body();
System.out.println(json);
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
TituloOmdb meuTituloOmdb = gson.fromJson(json, TituloOmdb.class);
System.out.println(meuTituloOmdb);
Titulo meuTitulo = new Titulo(meuTituloOmdb);
System.out.println(meuTitulo);
}
}