1
我有我的應用程序的按鈕,我希望當我按下按鈕的應用程序發送一個字符串到websrvice和得到的結果,這是我的代碼:安卓:在按下按鈕獲得java.io.EOFException的
btn = (Button) findViewById(R.id.button_add_to_cart);
btn.setTypeface(typeface);
btn.setEnabled(false);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
env.encodingStyle="utf-8";
request = new SoapObject("customWebService",
"add");
request.addProperty("sessionID", sessionId);
env.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(
"http://mywebsiteee.com/WebService/server.php?wsdl/",
60000);
androidHttpTransport.debug = true;
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.call("", env);
SoapObject result = (SoapObject)env.bodyIn;
String Test1 = result.getPropertyAsString(0);
String str = env.bodyIn.toString();
String s = Test1;
byte[] b = s.getBytes("UTF-8");
s = new String(b, "UTF-8");
try {
JSONObject jsonObject = new JSONObject(Test1);
s = jsonObject.getString("result");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
我的問題是,當我按下按鈕,我第一次得到這個錯誤:
java.io.EOFException的
這是完整的日誌:
07-27 07:47:25.059: W/System.err(1251): java.io.EOFException
07-27 07:47:25.059: W/System.err(1251): at libcore.io.Streams.readAsciiLine(Streams.java:203)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:579)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
07-27 07:47:25.059: W/System.err(1251): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.ServiceConnectionSE.getResponseCode(ServiceConnectionSE.java:103)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
07-27 07:47:25.059: W/System.err(1251): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
07-27 07:47:25.059: W/System.err(1251): at com.tashilgostar.tashilgostarstore.ProductActivity$5.onClick(ProductActivity.java:294)
07-27 07:47:25.059: W/System.err(1251): at android.view.View.performClick(View.java:4240)
07-27 07:47:25.059: W/System.err(1251): at android.view.View$PerformClick.run(View.java:17721)
07-27 07:47:25.059: W/System.err(1251): at android.os.Handler.handleCallback(Handler.java:730)
07-27 07:47:25.059: W/System.err(1251): at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 07:47:25.059: W/System.err(1251): at android.os.Looper.loop(Looper.java:137)
07-27 07:47:25.059: W/System.err(1251): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-27 07:47:25.059: W/System.err(1251): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 07:47:25.059: W/System.err(1251): at java.lang.reflect.Method.invoke(Method.java:525)
07-27 07:47:25.059: W/System.err(1251): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-27 07:47:25.059: W/System.err(1251): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-27 07:47:25.059: W/System.err(1251): at dalvik.system.NativeStart.main(Native Method)
但過了一段時間我按下按鈕或當我長時間按下它時,它的工作正常! 任何機構可以幫助我知道爲什麼會發生這種情況?