我将我的Android应用程序与webservice .asmx连接... 我收到一个错误,如IOException没有这样的文件或目录。我在下面给出了我的代码..我正在获取toast消息“请稍后再试”,所以一般例外正在发生。
webserviceCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new login().execute();
}
});
}
class login extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(Sample1_Page.this);
@Override
protected void onPreExecute() {
this.dialog.setMessage("Loading data");
this.dialog.show();
}
@Override
protected Void doInBackground(Void... unused) {
final String NAMESPACE = "https://xxx.xxxx.com/";
final String URL = "https://xxx.xxxx.xxx.com/appservice/d_service.asmx";
final String SOAP_ACTION = "https://xxxx.xxx.com/mLo";
final String METHOD_NAME = "mLo";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("userid", userid);
request.addProperty("password", password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String responseJSON=response.toString();
JSONArray jarray =new JSONArray(responseJSON);
Name=jarray.getJSONObject(0).getString(TAG_NAME);
Id=jarray.getJSONObject(0).getString(TAG_ID);
System.out.println(request);
System.out.println(responseJSON);
}
catch(SocketTimeoutException e){
timeoutexcep=true;
e.printStackTrace();
}
catch(UnknownHostException e){
httpexcep=true;
e.printStackTrace();
}
catch (Exception e) {
genexcep=true;
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if(timeoutexcep){
Toast.makeText(Sample1_Page.this, "Unable to connect to server, Please try again later",Toast.LENGTH_LONG).show();
}
else if(httpexcep){
Toast.makeText(Sample1_Page.this, "Please check your Internet connection",Toast.LENGTH_LONG).show();
}
else if(genexcep){
Toast.makeText(Sample1_Page.this, "Please try later",Toast.LENGTH_LONG).show();
}
else{
tableview();
}
timeoutexcep=false;
httpexcep=false;
genexcep=false;
}
public void tableview(){
try{
TextView webserviceResponse = (TextView) findViewById(R.id.textView1);
webserviceResponse.setText(Name);
}
catch(Exception e){
}
}
}
logcat的
Java.io.IOException: Errror running exec(). Command: [su] Working Directory: null Environment : null
at java.lang.ProcessManager. exec(ProcessManager.java.211)
at java.lang.Runtime.exec(Runtime.java : 168)
at java lang.Runtime. exec(Runtime.java : 241)
at java.lang.Runtime.exec (Runtime.java:248)
at android.os.AsyncTask&2.call(AsyncTask.java:287)
at java.util.concurrent.futureTask$Sync.innerRun(FutureTask.java:305
caused by: java.io.IOExceptio: No such file or directory
答案 0 :(得分:-1)
你能告诉我你的明显权限吗?
您必须拥有此权限。如果没有,那就添加它。
android.permission.WRITE_EXTERNAL_STORAGE
还要检查您的网络服务协议,是https还是http?尝试使用服务器的IP地址。它可能对你有所帮助。