错误消耗android的在线web服务

时间:2015-03-12 05:41:17

标签: java android eclipse web-services import

我已经创建了在本地机器上工作的webservice,并且我已经在android应用程序中成功使用它而没有任何错误。但是当我在在线服务器上托管我的web服务时,我遇到致命的错误异常。下面是我的android代码和错误日志。

错误日志: -

    03-12 10:57:54.935: W/dalvikvm(7491): threadid=15: thread exiting with uncaught exception (group=0x420d8898)
03-12 10:57:54.935: E/AndroidRuntime(7491): FATAL EXCEPTION: AsyncTask #4
03-12 10:57:54.935: E/AndroidRuntime(7491): java.lang.RuntimeException: An error occured while executing doInBackground()
03-12 10:57:54.935: E/AndroidRuntime(7491):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.lang.Thread.run(Thread.java:841)
03-12 10:57:54.935: E/AndroidRuntime(7491): Caused by: java.lang.NullPointerException
03-12 10:57:54.935: E/AndroidRuntime(7491):     at com.example.test.MainActivity$MyAsyncTask1.doInBackground(MainActivity.java:106)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at com.example.test.MainActivity$MyAsyncTask1.doInBackground(MainActivity.java:1)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-12 10:57:54.935: E/AndroidRuntime(7491):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-12 10:57:54.935: E/AndroidRuntime(7491):     ... 4 more
03-12 10:57:54.965: I/Process(7491): Sending signal. PID: 7491 SIG: 9

我的andorid代码: -

    package com.example.test;


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.support.v7.app.ActionBarActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {
    EditText name;
    TextView email;
    Button Btnfetch;
    String[] arr;
    private Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try
            {
                name = (EditText)findViewById(R.id.name);
                email = (TextView)findViewById(R.id.email);

                Btnfetch = (Button)findViewById(R.id.button1);
                Btnfetch.setOnClickListener(new OnClickListener()
                {

                    @Override
                    public void onClick(View v)
                    {
                        String sname = name.getText().toString();
                        String[] params = new String[]{"my_ip_address of webservice/",sname};
                        new MyAsyncTask1().execute(params);

                    }

                });
            }
            catch(Exception ex)
            {
                //Message(ex);
                Toast.makeText(this, "null", Toast.LENGTH_LONG).show();
            }


    }
    class MyAsyncTask1 extends AsyncTask<String, Void, String> 
    {
        public String SOAP_ACTION = "http://tempuri.org/Getemail";
        public String OPERATION_NAME = "Getemail";
        public String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
        public String SOAP_ADDRESS;
        private SoapObject request;
        private HttpTransportSE httpTransport;

        Object response = null;
        //this method will fetch output from webservice


        @Override
        protected String doInBackground(String... params)
        {
            SOAP_ADDRESS = "http://"+params[0]+"PCGws.asmx";
            request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
            PropertyInfo pi = new PropertyInfo();
            pi.setName("Name");
            pi.setValue(params[1]);
            pi.setType(String.class);
            request.addProperty(pi);
            pi = new PropertyInfo();


            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            httpTransport = new HttpTransportSE(SOAP_ADDRESS);
            try
            {

                httpTransport.call(SOAP_ACTION, envelope);
                response = envelope.getResponse();
                Log.d("result", response.toString());

            }
            catch(Exception exp)
            {
                response = exp.getMessage();
            }
            return response.toString();
        }
        protected void onPostExecute(final String result)
        {
            //result parameter should be final so that it can be use in cross thread operation
            super.onPostExecute(result);
            //we have to use async handler to make changes in view text
            mHandler.post(new Runnable()
            {
                @Override
                public void run()
                {
                    arr=result.split(",");
                    email.setText(arr[0]);


                }

            });


        }
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案