Java Android套接字已关闭错误
我正在开发一个android应用程序,我正在尝试连接服务器进行用户名验证。。我收到一个错误“java.net.socketException:Socket已关闭”。。。我在下面给出我的代码,如果有人能帮忙,请帮忙 主要活动Java Android套接字已关闭错误,java,android,sockets,Java,Android,Sockets,我正在开发一个android应用程序,我正在尝试连接服务器进行用户名验证。。我收到一个错误“java.net.socketException:Socket已关闭”。。。我在下面给出我的代码,如果有人能帮忙,请帮忙 主要活动 webserviceCallButton = (Button)findViewById(R.id.login_Button); etUserName = (EditText)findViewById(R.id.editTextLogin);
webserviceCallButton = (Button)findViewById(R.id.login_Button);
etUserName = (EditText)findViewById(R.id.editTextLogin);
etPassword = (EditText)findViewById(R.id.editTextPassword);
webserviceResponse = (TextView) findViewById(R.id.textView1);
webserviceCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
webserviceResponse.setText("Requesting to server .....");
//Create Webservice class object
WebserviceCall com = new WebserviceCall();
// Initialize variables
String id = "99999999999";
String password = "01233333";
//Call Webservice class method and pass values and get response
String aResponse = com.getmLogin("mLo",id,password);
//Alert message to show webservice response
Toast.makeText(getApplicationContext(), id+" id= "+aResponse+" hi",
Toast.LENGTH_LONG).show();
Log.i("AndroidExampleOutput", "----"+aResponse);
webserviceResponse.setText("Response : "+aResponse);
}
});
}
WebserviceCall
String namespace = "https://xxxx.xxxx.com/";
private String url = "https://xxxx.xxxx.xxxxxx.com/appservice/d_service.asmx";
String SOAP_ACTION = "https://xxxxx.com/mLo";
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
AndroidHttpTransport androidHttpTransport;
WebserviceCall() {
}
/**
* Set Envelope
*/
protected void SetEnvelope() {
try {
// Creating SOAP envelope
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//You can comment that line if your web service is not .NET one.
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new AndroidHttpTransport(url);
androidHttpTransport.debug = true;
} catch (Exception e) {
System.out.println("Soap Exception---->>>" + e.toString());
}
}
// MethodName variable is define for which webservice function will call
public String getmLogin(String mLo, String customerid,
String customername)
{
try {
//SOAP_ACTION = namespace + MethodName;
//SOAP_ACTION = namespace + MethodName;
//Adding values to request object
request = new SoapObject(namespace, mLo);
//Adding String value to request object
request.addProperty("customerid", "" + customerid);
request.addProperty("customername", "" + customername);
SetEnvelope();
try {
//SOAP calling webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
//Got Webservice response
String result = envelope.getResponse().toString();
return result;
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
} catch (Exception e) {
// TODO: handle exception
return e.toString();
}
}
此异常表示您已关闭套接字并尝试再次使用它 如果关闭输入或输出流,它将自动关闭另一个流和套接字
完成后只需关闭即可发布堆栈跟踪,如果它来自尚未发布的代码,也可以发布。@Jocheved我在代码段中看不到对.close()的调用,您在其他地方有调用吗?我正在工作,因此无法完全提交。不,这是我的完整代码…@不接受代码的Jocheved链接。在你的问题中,你需要发布一段显示问题的最短代码。我在这里给出的代码是我的完整代码。。但我无法找出其中的任何错误。。。但是我得到的错误是套接字已关闭。。。