私は Android を初めて使用し、ここ数日間何かに行き詰まっています。データベースから取得して、にあるCandidateNames
my に保存し、Java クライアントに返します。ArrayList
WebService
ArrayList
WebService
とArrayList
:
public ArrayList<String> DisplayName(){
ArrayList<String> results= new ArrayList<String>();
try {
String connectionURL = "jdbc:mysql://localhost/databaseName";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection=DriverManager.getConnection(connectionURL,"username","pswd");
statement = connection.createStatement();
String QueryString = "Select CName From CMaster where cid='xyz'";
rs = statement.executeQuery(QueryString);
while (rs.next()) {
results.add(rs.getString(1));
}
rs.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
Java コード:
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
envelope.setOutputSoapObject(request);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
System.out.println("Response:::::::::::::" +result);
}
これにより、 my の最初の値のみが得られますArrayList
。置き換えるSoapPrimitive response = (SoapPrimitive)envelope.getResponse();
と:
SoapObject result= (SoapObject)envelope.getResponse();
System.out.println("Response:::::::::::::" +result.getProperty(0));
次をスローしますexception
:
java.lang.classcastexception org.ksoap2.serialization.soapprimitive cannot be cast to org.ksoap2.serialization.soapObject
私はググって、可能な限りあらゆることを試しました。何かを見逃した場合は助けてください。前もって感謝します!