2013-02-10 135 views
0

我沒有在LogCat中發生錯誤。在代碼中顯示的IP是本地主機IP地址。我的AVD中有互聯網的可用性。面對Java.net.SocketException:權限被拒絕

我MainActivity.java是:

公共類MainActivity擴展活動{

private static final String SOAP_ACTION = "http://tempuri.org/add"; 
private static final String METHOD_NAME = "add"; 
private static final String NAMESPACE = "http://tempuri.org/"; 
private static final String URL = "http://101.63.111.137/yash/DemoService.asmx"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    Button callMe = (Button) findViewById(R.id.b1); 
    callMe.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      String responseData = getData(); 
      ((TextView) findViewById(R.id.textView1)).setText("Response Received is: " + responseData); 
     } 

    }); 

} 

private String getData() { 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

    PropertyInfo pi = new PropertyInfo(); 
    pi.setName("i"); 
    pi.setValue(((EditText) findViewById(R.id.e1)).getText().toString()); 
    pi.setType(int.class); 
    request.addProperty(pi); 

    PropertyInfo pi2 = new PropertyInfo(); 
    pi2.setName("j"); 
    pi2.setValue(((EditText) findViewById(R.id.e2)).getText().toString()); 
    pi2.setType(int.class); 
    request.addProperty(pi2); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 

    HttpTransportSE androidHttpTransport=new HttpTransportSE(URL); 
    try { 
     androidHttpTransport.call(SOAP_ACTION, envelope); 
     SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); 
     return response.toString(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     return e.toString(); 
    } 
} 

}

我已經添加在AndroidManifest.xml這些線路

謝謝提前。

回答

2

您是否向您的Manifest添加了INTERNET_ACCESS權限?

<manifest xlmns:android...> 
    ... 
    <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
</manifest> 

SocketException

+0

增加這些線路的許可行之後是表示拒絕連接例外:Java.net.ConnectException。 – Yash 2013-02-10 11:54:48

+0

我已經解決了,先生。謝謝。 – Yash 2013-02-10 12:00:24

+0

不客氣,但你應該接受答案,如果你解決了。 :) – Enrichman 2013-02-10 12:20:36

相關問題