2013-01-24 92 views
1

我已經在andoird清單頁面中包含了Internet Permissions,仍然錯誤仍然存​​在。我也在類似的代碼中收到了一個未知的宿主激勵。請引導我!泰! :)如何解決java.net.SocketException權限被拒絕的錯誤?

package name.id; 

import android.app.Activity; 
import android.content.DialogInterface.OnClickListener; 
import android.os.Bundle; 
import org.ksoap2.*; 
import org.ksoap2.serialization.*; 
import org.ksoap2.transport.*; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class FirstPage extends Activity implements android.view.View.OnClickListener 
{ 
    /** Called when the activity is first created. */ 

    TextView tv; 
    Button bu; 
    EditText et; 

    private static final String SOAP_ACTION="http://lthed.com/GetFullNamefromUserID"; 
    private static final String METHOD_NAME="GetFullNamefromUserID"; 
    private static final String NAMESPACE="http://lthed.com"; 
    private static final String URL="http://vpwdvws09/services/DirectoryService.asmx"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     et=(EditText) findViewById(R.id.editText1); 
     tv=(TextView) findViewById(R.id.textView2); 
     bu=(Button) findViewById(R.id.button1); 
     bu.setOnClickListener((android.view.View.OnClickListener) this); 
     tv.setText(""); 
    } 

    public void onClick(View v) 
    {   
     // creating the soap request and all its paramaters 
     SoapObject request= new SoapObject(NAMESPACE, METHOD_NAME); 
     //request.addProperty("ID","89385815");// hardcoding some random value 
     //we can also take in a value in a var and pass it there 


     //set soap envelope,set to dotnet and set output 
     SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     soapEnvelope.dotNet=true; 
     soapEnvelope.setOutputSoapObject(request); 

     HttpTransportSE obj = new HttpTransportSE(URL); 
     //to make call to server 
     try 
     { 
      obj.call(SOAP_ACTION,soapEnvelope);// in out parameter 
      SoapPrimitive resultString=(SoapPrimitive)soapEnvelope.getResponse(); 
      //soapObject or soapString 
      tv.setText("Status : " + resultString); 
     } 
     catch(Exception e) 
     { 
      tv.setText("Error : " + e.toString()); 
      //e.printStackTrace(); 
     } 

} 
} 

回答

1

錯誤被拋出,因爲在網址中出現錯誤。 URL需要我的IP地址才能正常工作,而不是我提供的URL,因爲Web服務無法理解。

2

你有沒有加入上網權限您的清單:

<uses-permission android:name="android.permission.INTERNET"/> 
+0

是的!就像我一樣,我也在清單頁面中添加了互聯網權限。它似乎仍在拋出一個錯誤。還是要謝謝你的幫助! –

0

取決於您使用的KSOAP2版本錯誤可能會有所不同。

其推薦使用KSOAP2 v3 + lib。

只需使用下面的代碼重寫......

StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()permitAll()建()。 StrictMode.setThreadPolicy(policy);

並且還使用...

相關問題