Estou desenvolvendo um aplicativo para loja, onde esse aplicativo só consome web service.
Estou com o seguinte erro na seguinte linha onde recupero a imagem em byte[], estou usando import Base64.
Segue Classe Lojas.java (aqui fica os Guetters e Setters)
public class Lojas {
private int id;
private String nome_da_oferta;
private String descricao;
private String tamanho;
private double valor;
private String dia1;
private String dia2;
private String dia3;
private byte[] imagem1;
private double horario;
public Lojas(){
}
public Lojas(String nome_da_oferta, int id, byte[] imagem1, String dia3, String dia2, String dia1, double valor, String tamanho, String descricao, double horario) {
this.nome_da_oferta = nome_da_oferta;
this.id = id;
this.imagem1 = imagem1;
this.dia3 = dia3;
this.dia2 = dia2;
this.dia1 = dia1;
this.valor = valor;
this.tamanho = tamanho;
this.descricao = descricao;
this.horario = horario;
}
public String getNome_da_oferta() {
return nome_da_oferta;
}
public void setNome_da_oferta(String nome_da_oferta) {
this.nome_da_oferta = nome_da_oferta;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public String getTamanho() {
return tamanho;
}
public void setTamanho(String tamanho) {
this.tamanho = tamanho;
}
public double getValor() {
return valor;
}
public void setValor(double valor) {
this.valor = valor;
}
public String getDia1() {
return dia1;
}
public void setDia1(String dia1) {
this.dia1 = dia1;
}
public String getDia2() {
return dia2;
}
public void setDia2(String dia2) {
this.dia2 = dia2;
}
public String getDia3() {
return dia3;
}
public void setDia3(String dia3) {
this.dia3 = dia3;
}
public byte[] getImagem1() {
return imagem1;
}
public void setImagem1(byte[] imagem1) {
this.imagem1 = imagem1;
}
public double getHorario() {
return horario;
}
public void setHorario(double horario) {
this.valor = valor;
}
}
Segue a Classe LojasDAO (nessa classe que está o erro onde citei no incio do post)
public class LojasDAO {
private static final String URL = "http://localhost/Mark-e/server.php?wsdl";
private static final String NAMESPACE = "http://localhost/soap/urn:server";
private static final String LOJAS_ITENS = "getLojas";
private static final String LOJAS_IMAGENS = "getLojas_imagem";
private static final String LOJAS_ESPORTES = "getEsporte";
private static final String LOJAS_ESPORTES_IMAGENS = "getEsporte_imagem";
private static final String CINEMA = "getCinema";
private static final String CINEMA_IMAGENS = "getCinema_imagem";
public Lojas getLojas(int id) {
Lojas ljs = null;
SoapObject getLojas = new SoapObject(NAMESPACE, LOJAS_ITENS);
getLojas.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getLojas);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + LOJAS_ITENS, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
ljs.setNome_da_oferta(resposta.getProperty("nome_da_oferta").toString());
ljs.setDescricao(resposta.getProperty("descricao").toString());
ljs.setTamanho(resposta.getProperty("tamanho").toString());
ljs.setValor(Integer.parseInt(resposta.getProperty("valor").toString()));
ljs.setDia1(resposta.getProperty("dia1").toString());
ljs.setDia2(resposta.getProperty("dia2").toString());
ljs.setDia3(resposta.getProperty("dia3").toString());
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
public Lojas getLojas_imagem (int id) {
Lojas ljs = null;
SoapObject getLojas_imagem = new SoapObject(NAMESPACE, LOJAS_IMAGENS);
getLojas_imagem.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getLojas_imagem);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + LOJAS_IMAGENS, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
String imagem1 = resposta.getProperty("imagem1").toString();
byte[] bt = Base64.encode(imagem1, Base64.DEFAULT);
ljs.setImagem1(bt);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
public Lojas getEsporte (int id) {
Lojas ljs = null;
SoapObject getEsporte = new SoapObject(NAMESPACE, LOJAS_ESPORTES);
getEsporte.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getEsporte);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + LOJAS_ESPORTES, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
ljs.setNome_da_oferta(resposta.getProperty("nome_da_oferta").toString());
ljs.setDescricao(resposta.getProperty("descricao").toString());
ljs.setTamanho(resposta.getProperty("tamanho").toString());
ljs.setValor(Integer.parseInt(resposta.getProperty("valor").toString()));
ljs.setDia1(resposta.getProperty("dia1").toString());
ljs.setDia2(resposta.getProperty("dia2").toString());
ljs.setDia3(resposta.getProperty("dia3").toString());
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
public Lojas getEsporte_imagem (int id) {
Lojas ljs = null;
SoapObject getEsporte_imagem = new SoapObject(NAMESPACE,LOJAS_ESPORTES_IMAGENS);
getEsporte_imagem.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getEsporte_imagem);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + LOJAS_ESPORTES_IMAGENS, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
String imagem1 = resposta.getProperty("imagem1").toString();
byte[] bt = Base64.encode(imagem1, Base64.DEFAULT);
ljs.setImagem1(bt);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
public Lojas getCinema (int id) {
Lojas ljs = null;
SoapObject getCinema = new SoapObject(NAMESPACE, CINEMA);
getCinema.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getCinema);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + CINEMA, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
ljs.setNome_da_oferta(resposta.getProperty("nome_da_oferta").toString());
ljs.setDescricao(resposta.getProperty("descricao").toString());
ljs.setHorario(Integer.parseInt(resposta.getProperty("horario").toString()));
ljs.setValor(Integer.parseInt(resposta.getProperty("valor").toString()));
ljs.setDia1(resposta.getProperty("dia1").toString());
ljs.setDia2(resposta.getProperty("dia2").toString());
ljs.setDia3(resposta.getProperty("dia3").toString());
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
public Lojas getCinema_imagem (int id) {
Lojas ljs = null;
SoapObject getCinema_imagem = new SoapObject(NAMESPACE,CINEMA_IMAGENS);
getCinema_imagem.addProperty("id", id);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(getCinema_imagem);
new MarshalBase64().register(envelope);
envelope.implicitTypes = true;
HttpTransportSE Http = new HttpTransportSE(URL);
try {
Http.call("ljs" + CINEMA_IMAGENS, envelope);
SoapObject resposta = (SoapObject) envelope.getResponse();
ljs = new Lojas();
ljs.setId(Integer.parseInt(resposta.getProperty("id").toString()));
String imagem1 = resposta.getProperty("imagem1").toString();
byte[] bt = Base64.encode(imagem1, Base64.DEFAULT);
ljs.setImagem1(bt);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ljs;
}
O erro está nessa linha, onde eu pego em String e converto para Byte[]. Eu defini na classe Lojas.java a imagem como byte[] e esse erro persiste.
String imagem1 = resposta.getProperty("imagem1").toString();
**byte[] bt = Base64.encode(imagem1, Base64.DEFAULT);**
ljs.setImagem1(bt);**
**E como ficaria pra chamar ela esse consumo na Activity principal ?**<img src="/uploads/default/original/3X/b/2/b2d2a53920c4f3a53866171e2c8c03208826cf03.png" width="690" height="387">