How get an ArrayList return from the WebService
I have a WebService with a method returns an ArrayList with two values, and in Android I need to save in another ArrayList but when i do the .add(), gives me an ArrayList with one value [string, string].
Here is the code form the WebService method:
@WebMethod(operationName = "mostarNombre")
public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {
String nomb = "";
ArrayList<String> list = new ArrayList<String>();
try {
DriverManager.registerDriver(new OracleDriver());
Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:xxx:xxx", xxxx, xxxx);
String query = "select * from ejemplo where id = 1";
Statement stmt = cn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
nomb = rs.getString("nombre");
String ids = rs.getString("id");
list.add(nomb);
list.add(ids);
}
} catch (SQLException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
And here is the code from my method in Android:
public void consultar(View v){
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
String resultadoFINAL;
//Creacion de la Solicitud
SoapObject request = new SoapObject(NAMESPACE, METHOD2);
//Creacion del Envelope
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
//Creacion del transporte
HttpTransportSE transporte = new HttpTransportSE(URL);
// Paso de parámetro
PropertyInfo numeroEmp = new PropertyInfo();
numeroEmp.setName("numero");
request.addProperty(numeroEmp);
//Llamada
transporte.call(SOAPACTION2, sobre);
//Resultado
Object resultado = (Object) sobre.getResponse();
ArrayList<String> lista = new ArrayList<String>();
lista.add(resultado.toString());
String a = lista.get(0);
tvConsulta.setText(lista.get(0));
tvEj.setText(lista.get(1));
}catch (Exception e) {
e.printStackTrace();
}
}
When I do the lista.get(0) I get one value like [string, string]. How I can solve this ?
EDIT:
The final solution is casting to Vector:
Vector lista = (Vector) sobre.getResponse();
java

add a comment |
I have a WebService with a method returns an ArrayList with two values, and in Android I need to save in another ArrayList but when i do the .add(), gives me an ArrayList with one value [string, string].
Here is the code form the WebService method:
@WebMethod(operationName = "mostarNombre")
public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {
String nomb = "";
ArrayList<String> list = new ArrayList<String>();
try {
DriverManager.registerDriver(new OracleDriver());
Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:xxx:xxx", xxxx, xxxx);
String query = "select * from ejemplo where id = 1";
Statement stmt = cn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
nomb = rs.getString("nombre");
String ids = rs.getString("id");
list.add(nomb);
list.add(ids);
}
} catch (SQLException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
And here is the code from my method in Android:
public void consultar(View v){
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
String resultadoFINAL;
//Creacion de la Solicitud
SoapObject request = new SoapObject(NAMESPACE, METHOD2);
//Creacion del Envelope
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
//Creacion del transporte
HttpTransportSE transporte = new HttpTransportSE(URL);
// Paso de parámetro
PropertyInfo numeroEmp = new PropertyInfo();
numeroEmp.setName("numero");
request.addProperty(numeroEmp);
//Llamada
transporte.call(SOAPACTION2, sobre);
//Resultado
Object resultado = (Object) sobre.getResponse();
ArrayList<String> lista = new ArrayList<String>();
lista.add(resultado.toString());
String a = lista.get(0);
tvConsulta.setText(lista.get(0));
tvEj.setText(lista.get(1));
}catch (Exception e) {
e.printStackTrace();
}
}
When I do the lista.get(0) I get one value like [string, string]. How I can solve this ?
EDIT:
The final solution is casting to Vector:
Vector lista = (Vector) sobre.getResponse();
java

add a comment |
I have a WebService with a method returns an ArrayList with two values, and in Android I need to save in another ArrayList but when i do the .add(), gives me an ArrayList with one value [string, string].
Here is the code form the WebService method:
@WebMethod(operationName = "mostarNombre")
public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {
String nomb = "";
ArrayList<String> list = new ArrayList<String>();
try {
DriverManager.registerDriver(new OracleDriver());
Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:xxx:xxx", xxxx, xxxx);
String query = "select * from ejemplo where id = 1";
Statement stmt = cn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
nomb = rs.getString("nombre");
String ids = rs.getString("id");
list.add(nomb);
list.add(ids);
}
} catch (SQLException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
And here is the code from my method in Android:
public void consultar(View v){
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
String resultadoFINAL;
//Creacion de la Solicitud
SoapObject request = new SoapObject(NAMESPACE, METHOD2);
//Creacion del Envelope
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
//Creacion del transporte
HttpTransportSE transporte = new HttpTransportSE(URL);
// Paso de parámetro
PropertyInfo numeroEmp = new PropertyInfo();
numeroEmp.setName("numero");
request.addProperty(numeroEmp);
//Llamada
transporte.call(SOAPACTION2, sobre);
//Resultado
Object resultado = (Object) sobre.getResponse();
ArrayList<String> lista = new ArrayList<String>();
lista.add(resultado.toString());
String a = lista.get(0);
tvConsulta.setText(lista.get(0));
tvEj.setText(lista.get(1));
}catch (Exception e) {
e.printStackTrace();
}
}
When I do the lista.get(0) I get one value like [string, string]. How I can solve this ?
EDIT:
The final solution is casting to Vector:
Vector lista = (Vector) sobre.getResponse();
java

I have a WebService with a method returns an ArrayList with two values, and in Android I need to save in another ArrayList but when i do the .add(), gives me an ArrayList with one value [string, string].
Here is the code form the WebService method:
@WebMethod(operationName = "mostarNombre")
public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {
String nomb = "";
ArrayList<String> list = new ArrayList<String>();
try {
DriverManager.registerDriver(new OracleDriver());
Connection cn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:xxx:xxx", xxxx, xxxx);
String query = "select * from ejemplo where id = 1";
Statement stmt = cn.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
nomb = rs.getString("nombre");
String ids = rs.getString("id");
list.add(nomb);
list.add(ids);
}
} catch (SQLException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
return list;
}
And here is the code from my method in Android:
public void consultar(View v){
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
String resultadoFINAL;
//Creacion de la Solicitud
SoapObject request = new SoapObject(NAMESPACE, METHOD2);
//Creacion del Envelope
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
sobre.dotNet = true;
sobre.setOutputSoapObject(request);
//Creacion del transporte
HttpTransportSE transporte = new HttpTransportSE(URL);
// Paso de parámetro
PropertyInfo numeroEmp = new PropertyInfo();
numeroEmp.setName("numero");
request.addProperty(numeroEmp);
//Llamada
transporte.call(SOAPACTION2, sobre);
//Resultado
Object resultado = (Object) sobre.getResponse();
ArrayList<String> lista = new ArrayList<String>();
lista.add(resultado.toString());
String a = lista.get(0);
tvConsulta.setText(lista.get(0));
tvEj.setText(lista.get(1));
}catch (Exception e) {
e.printStackTrace();
}
}
When I do the lista.get(0) I get one value like [string, string]. How I can solve this ?
EDIT:
The final solution is casting to Vector:
Vector lista = (Vector) sobre.getResponse();
java

java

edited Nov 23 '18 at 15:33
Beardman
asked Nov 21 '18 at 19:31
BeardmanBeardman
76
76
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
lista.add(resultado.toString());
first you have to understand what toString do.
toString method return the refrence of object by default if you not override it.That why its store only one value that is reference of array list return from webservice.
do this
1- if its return array list then assign it in arraylist directly.
eg
ArrayList<String> lista=sobre.getResponse();
2- just iterate over result and add in list.there are a no of way to iterate over list.i use simple for each loop.
for(String value:resultdo){
lista.add(value);
}
I can't doArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object
– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution wasVector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419310%2fhow-get-an-arraylist-return-from-the-webservice%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
lista.add(resultado.toString());
first you have to understand what toString do.
toString method return the refrence of object by default if you not override it.That why its store only one value that is reference of array list return from webservice.
do this
1- if its return array list then assign it in arraylist directly.
eg
ArrayList<String> lista=sobre.getResponse();
2- just iterate over result and add in list.there are a no of way to iterate over list.i use simple for each loop.
for(String value:resultdo){
lista.add(value);
}
I can't doArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object
– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution wasVector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
add a comment |
lista.add(resultado.toString());
first you have to understand what toString do.
toString method return the refrence of object by default if you not override it.That why its store only one value that is reference of array list return from webservice.
do this
1- if its return array list then assign it in arraylist directly.
eg
ArrayList<String> lista=sobre.getResponse();
2- just iterate over result and add in list.there are a no of way to iterate over list.i use simple for each loop.
for(String value:resultdo){
lista.add(value);
}
I can't doArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object
– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution wasVector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
add a comment |
lista.add(resultado.toString());
first you have to understand what toString do.
toString method return the refrence of object by default if you not override it.That why its store only one value that is reference of array list return from webservice.
do this
1- if its return array list then assign it in arraylist directly.
eg
ArrayList<String> lista=sobre.getResponse();
2- just iterate over result and add in list.there are a no of way to iterate over list.i use simple for each loop.
for(String value:resultdo){
lista.add(value);
}
lista.add(resultado.toString());
first you have to understand what toString do.
toString method return the refrence of object by default if you not override it.That why its store only one value that is reference of array list return from webservice.
do this
1- if its return array list then assign it in arraylist directly.
eg
ArrayList<String> lista=sobre.getResponse();
2- just iterate over result and add in list.there are a no of way to iterate over list.i use simple for each loop.
for(String value:resultdo){
lista.add(value);
}
answered Nov 21 '18 at 19:47
jogendrajogendra
945
945
I can't doArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object
– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution wasVector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
add a comment |
I can't doArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object
– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution wasVector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
I can't do
ArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object– Beardman
Nov 21 '18 at 20:08
I can't do
ArrayList<String> lista = sobre.getResponse();
Incompatible types, required ArrayList, found Object– Beardman
Nov 21 '18 at 20:08
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
As i see your method is returning ArrayList<String> @WebMethod(operationName = "mostarNombre") public ArrayList<String> mostarNombre(@WebParam(name = "id") int id) {} try to cast it explicitly using ArrayList<String> lista = (ArrayList<String>)sobre.getResponse();
– jogendra
Nov 23 '18 at 4:33
Thaaaanks for the idea of cast, but the final solution was
Vector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
Thaaaanks for the idea of cast, but the final solution was
Vector lista = (Vector)sobre.getResponse();
– Beardman
Nov 23 '18 at 15:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419310%2fhow-get-an-arraylist-return-from-the-webservice%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown