Boa Tarde,
Pessoal alguém poderia me ajudar na Implementação do Retrofit2, está retornando erro e já li a documentação, porém estou com dificuldades.
Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
Information:BUILD FAILED
Information:Total time: 19.279 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
02-01 10:55:19.402 1828-1836/? W/MessageQueue: Handler (android.os.Handler) {2df742d} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (android.os.Handler) {2df742d} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:543)
at android.os.Handler.enqueueMessage(Handler.java:643)
at android.os.Handler.sendMessageAtTime(Handler.java:612)
at android.os.Handler.sendMessageDelayed(Handler.java:582)
at android.os.Handler.post(Handler.java:338)
at android.os.ResultReceiver$MyResultReceiver.send(ResultReceiver.java:57)
at com.android.internal.os.IResultReceiver$Stub.onTransact(IResultReceiver.java:58)
at android.os.Binder.execTransact(Binder.java:565)
Abaixo minha Implementação.
Metodo Main
package victoroliveira.com.br.loja;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import victoroliveira.com.br.loja.Models.cliente;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private static final String TAG = "ERRO" ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(clienteService.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
clienteService service = retrofit.create(clienteService.class);
Call<List<cliente>> call = service.getcliente();
call.enqueue(new Callback<List<cliente>>() {
@Override
public void onResponse(Call<List<cliente>> call, Response<List<cliente>> response) {
if (!response.isSuccessful()){
Log.i("TAG","ERRO: " + response.code());
}else{
}
}
@Override
public void onFailure(Call<List<cliente>> call, Throwable t) {
Log.e(TAG,"ERRO: " + t.getMessage());
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final FloatingActionButton fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent fab = new Intent(MainActivity.this,TelaAdd.class);
startActivity(fab);
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
METODO INTERFACE
package victoroliveira.com.br.loja;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
import victoroliveira.com.br.loja.Models.cliente;
/**
* Created by Victor Oliveira on 30/01/2017.
*/
public interface clienteService {
public static final String BASE_URL = "http://192.168.0.143:21590/Mobile/services/";
@GET("{cliente}")
Call<List<cliente>> getcliente();
}
CLASSE cliente
package victoroliveira.com.br.loja.Models;
/**
* Created by Victor Oliveira on 30/01/2017.
*/
public class cliente {
private Long id;
private String nome;
private Long cpf;
private String produto;
private String logradouro;
private String n;
private String cidade;
private String pais;
private Long telefone;
private String razaosocial;
private String nomefantasia;
private String username;
private String senha;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Long getCpf() {
return cpf;
}
public void setCpf(Long cpf) {
this.cpf = cpf;
}
public String getProduto() {
return produto;
}
public void setProduto(String produto) {
this.produto = produto;
}
public String getLogradouro() {
return logradouro;
}
public void setLogradouro(String logradouro) {
this.logradouro = logradouro;
}
public String getN() {
return n;
}
public void setN(String n) {
this.n = n;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getPais() {
return pais;
}
public void setPais(String pais) {
this.pais = pais;
}
public Long getTelefone() {
return telefone;
}
public void setTelefone(Long telefone) {
this.telefone = telefone;
}
public String getRazaosocial() {
return razaosocial;
}
public void setRazaosocial(String razaosocial) {
this.razaosocial = razaosocial;
}
public String getNomefantasia() {
return nomefantasia;
}
public void setNomefantasia(String nomefantasia) {
this.nomefantasia = nomefantasia;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}