尝试使用方法时出现xmlpullparser异常

时间:2013-04-16 10:27:38

标签: android

我正在尝试使用ksaop2来使用webservice方法。

这是代码

公共类CityData扩展了AsyncTask {

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        dialog.dismiss();
        try {
            if (!lstresponse.isEmpty()) {
                lstresult.addAll(lstresponse);
                lstcities.setAdapter(CustAdapter);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(LocationbyCities.this, "No net connection/very weak signal",
                    Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    @Override
    protected String doInBackground(Integer... params) {
        // TODO Auto-generated method stub

        SendRequesttoServer();

        return "1";
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        dialog = new ProgressDialog(LocationbyCities.this);
        dialog.setMessage("Please Wait...");
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();

    }

}

public void SendRequesttoServer() {

    try {

        SOAP_ACTION = NAMESPACE + METHOD;

        SoapObject request = new SoapObject(NAMESPACE, METHOD);

        SoapSerializationEnvelope res = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        res.dotNet = true;
        res.setOutputSoapObject(request);

        HttpTransportSE call = new HttpTransportSE(url);

        SoapPrimitive result;
        call.call(SOAP_ACTION, res);
        result = (SoapPrimitive) res.getResponse();
        ParseLocations Objparsecities = new ParseLocations(
                new ByteArrayInputStream(result.toString()
                        .getBytes("UTF-8")));
        lstresponse = Objparsecities.parse();

        System.out.println(lstresponse);

    } catch (SoapFault e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

它在模拟器上工作正常,但当我尝试在我的设备上运行时,我收到以下错误

04-16 15:54:11.761: W/System.err(3982): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@405f2fe8) 
04-16 15:54:11.761: W/System.err(3982):     at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)
04-16 15:54:11.761: W/System.err(3982):     at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:1413)
04-16 15:54:11.761: W/System.err(3982):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
04-16 15:54:11.761: W/System.err(3982):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
04-16 15:54:11.761: W/System.err(3982):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
04-16 15:54:11.761: W/System.err(3982):     at com.netserv.Pungry.LocationbyCities.SendRequesttoServer(LocationbyCities.java:249)
04-16 15:54:11.761: W/System.err(3982):     at com.netserv.Pungry.LocationbyCities$CityData.doInBackground(LocationbyCities.java:216)
04-16 15:54:11.761: W/System.err(3982):     at com.netserv.Pungry.LocationbyCities$CityData.doInBackground(LocationbyCities.java:1)
04-16 15:54:11.761: W/System.err(3982):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-16 15:54:11.761: W/System.err(3982):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-16 15:54:11.761: W/System.err(3982):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-16 15:54:11.761: W/System.err(3982):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-16 15:54:11.761: W/System.err(3982):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-16 15:54:11.761: W/System.err(3982):     at java.lang.Thread.run(Thread.java:1027)
04-16 15:54:11.771: W/System.err(3982): java.lang.NullPointerException
04-16 15:54:11.771: W/System.err(3982):     at com.netserv.Pungry.LocationbyCities$CityData.onPostExecute(LocationbyCities.java:202)
04-16 15:54:11.771: W/System.err(3982):     at com.netserv.Pungry.LocationbyCities$CityData.onPostExecute(LocationbyCities.java:1)
04-16 15:54:11.771: W/System.err(3982):     at android.os.AsyncTask.finish(AsyncTask.java:417)
04-16 15:54:11.771: W/System.err(3982):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-16 15:54:11.771: W/System.err(3982):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-16 15:54:11.771: W/System.err(3982):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 15:54:11.771: W/System.err(3982):     at android.os.Looper.loop(Looper.java:150)
04-16 15:54:11.771: W/System.err(3982):     at android.app.ActivityThread.main(ActivityThread.java:4263)
04-16 15:54:11.771: W/System.err(3982):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 15:54:11.771: W/System.err(3982):     at java.lang.reflect.Method.invoke(Method.java:507)
04-16 15:54:11.771: W/System.err(3982):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-16 15:54:11.771: W/System.err(3982):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-16 15:54:11.781: W/System.err(3982):     at dalvik.system.NativeStart.main(Native Method)

我能知道这是什么错误吗?

现在我注意到,如果它们的信号很弱,就会发生这种错误。否则它工作正常。我也正在检查网络状态。我仍然得到这个错误。我该如何解决?

感谢:)

0 个答案:

没有答案