本文介绍了我没有从andriod调用我的Web服务抛出异常networkonmainthreadexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package com.example.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.*;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private static String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "HelloWorld";
private static String URL = "http://117.227.58.74/vehicle//WebService.asmx";
String weight = "77";
String fromUnit = "78";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//tv =(TextView)findViewById(R.id.textView1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("lat");
weightProp.setValue(weight);
weightProp.setType(double.class);
Request.addProperty(weightProp);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("log");
fromProp.setValue(fromUnit);
fromProp.setType(double.class);
Request.addProperty(fromProp);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
Toast.makeText(getBaseContext(),"1",Toast.LENGTH_LONG).show();
HttpTransportSE aht = new HttpTransportSE(URL);
try
{
Toast.makeText(getBaseContext(),"2",Toast.LENGTH_LONG).show();
aht.call(SOAP_ACTION, soapEnvelope);
Toast.makeText(getBaseContext(),"3",Toast.LENGTH_LONG).show();
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
Toast.makeText(getBaseContext(),"4",Toast.LENGTH_LONG).show();
//Log.i("myApp", response.toString());
//tv.setText("Status:" + resultString);
} catch (Exception e)
{
e.printStackTrace();
}
}
}
推荐答案
这篇关于我没有从andriod调用我的Web服务抛出异常networkonmainthreadexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!