public String SQLInsert(String Conn, String Query)
{
SoapObject request = new
SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("Conn");
pi.setValue(Conn);
pi.setType(String.class);
request.addProperty(pi);
pi = new PropertyInfo();
pi.setName("Query");
pi.setValue(Query);
pi.setType(String.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
Object response = null;
try {
httpTransport.call(SOAP_ACTION,envelope);
response = envelope.getResponse();
}catch(Exception exception){
response = exception.toString();
}
return response.toString();
}
response = envelope.getResponse();// error occurs at this line.
有时用于显示java.net.SockettimeoutException
,现在显示android.os.NetworkOnMainThreadException
。我想要一个很好的解决方案,可以长期帮助我。
答案 0 :(得分:0)
现在显示android.os.NetworkOnMainThreadException
实际上只有在主线程中执行网络相关代码时才会出现上述异常,因此要解决此问题,您必须使用Thread
或AsyncTask
。
Thread t=new Thread(){
public void run(){
SQLInsert(Conn,Query);
}
}
因此,如果要执行SQLInsert( - , - )方法,只需按以下步骤启动Thread
t.start();
希望这会对你有所帮助。