android:按下按钮获取java.io.EOFException

时间:2014-07-27 07:57:24

标签: java android web-services button eofexception

我在我的应用程序中有一个按钮,当我按下按钮应用程序发送一个字符串到websrvice并获得结果时,这是我的代码:

    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)

但是过了一段时间我按下按钮或长按它很长时间才能正常工作! 任何身体可以帮助我知道为什么会这样吗?

0 个答案:

没有答案