Java 计数值通过soap Web服务显示在android emulator上
我曾尝试在Android中显示一个值,该值是通过soap调用检索的。但我不能让它工作。如果我运行我的应用程序,计数值将显示在我的tomcat apache上。但是我的android仿真器上没有显示计数值。为什么这里不显示计数值。 请帮帮我。我知道原因。但我搞不懂代码部分。我的错误是我的android代码部分。在那里我可以更改我的代码 这是我的Web服务代码:Java 计数值通过soap Web服务显示在android emulator上,java,android,mysql,soap,Java,Android,Mysql,Soap,我曾尝试在Android中显示一个值,该值是通过soap调用检索的。但我不能让它工作。如果我运行我的应用程序,计数值将显示在我的tomcat apache上。但是我的android仿真器上没有显示计数值。为什么这里不显示计数值。 请帮帮我。我知道原因。但我搞不懂代码部分。我的错误是我的android代码部分。在那里我可以更改我的代码 这是我的Web服务代码: public class RetailerWs { public String customerData(){ String custo
public class RetailerWs {
public String customerData(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("select * from xcart_orders where status='Q' AND date = CURDATE()");
ResultSet result = statement.executeQuery();
int count=0;
while(result.next()){
count++;
System.out.println(count);
}
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}
}
这是我的android代码部分:
public class RetailerActivity extends Activity {
private static final String SOAP_ACTION = "http://xcart.com/customerData";
private static final String METHOD_NAME = "customerData";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8085/XcartLogin/services/RetailerWs?wsdl";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retrieve);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");//Result string will split & store in an array
TextView tv = new TextView(this);
for(int i = 0; i<resultArr.length;i++){
tv.append(resultArr[i]+"\n\n");
}
setContentView(tv);
} catch (Exception e) {
e.printStackTrace();
}
}
}
公共类RetailerActivity扩展活动{
私有静态最终字符串SOAP_ACTION=”http://xcart.com/customerData";
私有静态最终字符串方法\u NAME=“customerData”;
私有静态最终字符串命名空间=”http://xcart.com";
私有静态最终字符串URL=”http://192.168.1.168:8085/XcartLogin/services/RetailerWs?wsdl";
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.retrieve);
SoapObject请求=新的SoapObject(名称空间、方法名称);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(请求);
HttpTransportSE ht=新的HttpTransportSE(URL);
试一试{
ht.呼叫(SOAP_动作、信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
SOAPs=响应;
字符串str=s.toString();
String resultArr[]=str.split(&);//结果字符串将拆分并存储在数组中
TextView tv=新的TextView(此);
对于(int i=0;i您确定您在TextView中获得了一些值吗?您可以按照以下方式在android中设置TextView
LinearLayout lLayout = (LinearLayout)findViewById(R.id.l_layout); // This is my main layout
TextView tv = new TextView(this);
tv.setText("Akshay"); // Here I set the value to TextView
lLayout.addView(tv); // Here I am adding this view in main View.
希望这有帮助:)