This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Socket Exception in Android

I am working on an Android Application in which I got stuck in an issue. The problem is that, "When I run this method mentioned below in code, I am getting an error of socket Exception ((Permission denied) i.e, java.net.SocketException: socket failed:). I tried many time to resolve this issue, but still getting experiencing this problem. I know this is an android developer forum community where I am seeking some solution. Please help me for resolving my query. Here is code please check and reply me asap.


<code>

  1. public void run() {
  2.    // TODO Auto-generated method stub
  3.    URL url = null;
  4. try {
  5.    url = new URL("http url");
  6. }
  7. catch (MalformedURLException me) {
  8.    // TODO Auto-generated catch block
  9.    me.printStackTrace();
  10. }
  11. try {
  12.    URLConnection uelCon = url.openConnection();
  13.    InputStreamReader inputStreamReader = new InputStreamReader(BufferedInputStream(myconn.getInputStream()));
  14.    BufferedReader buffer = new BufferedReader(inputStreamReader);
  15.    String traverse;
  16.    StringBuilder builder = new StringBuilder();
  17.    while ((traverse=buffer.readLine()) != null)
  18.    {
  19.        builder.append(traverse);
  20.    }
  21. }
  22. catch (IOException ioe) {
  23.    // TODO Auto-generated catch block
  24.    ioe.printStackTrace();
  25. }
  26. super.run();
  27. }

</code>

Parents
  • Have you set up your Manifest xml file to get permission to access the internet? i.e.

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

    If you haven't, you need to inform any user of your app of the permissions you're requesting before you can use a resource.

Reply
  • Have you set up your Manifest xml file to get permission to access the internet? i.e.

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

    If you haven't, you need to inform any user of your app of the permissions you're requesting before you can use a resource.

Children
No data