1. Download our Official Android App: Forums for Android!

Apps What is wrong with this code?

Discussion in 'Android Development' started by MIIISTER NEUGIT, Nov 12, 2010.

  1. MIIISTER NEUGIT

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    17
    Joined:
    Nov 12, 2010

    Nov 12, 2010
    17
    0
    15
    Xbox 360 Game Developer
    I have the following code:


    public static String[] GetCategories(APPCLASS i) throws IOException
    {
    URL url = new URL("http://192.168.1.72/getcategories.php");
    URLConnection conn = url.openConnection();
    InputStream is = conn.getInputStream();

    Writer writer = new StringWriter();

    char[] buffer = new char[1024];
    try {
    Reader reader = new BufferedReader(
    new InputStreamReader(is, "UTF-8"));
    int n;
    while ((n = reader.read(buffer)) != -1) {
    writer.write(buffer, 0, n);
    }
    } finally {
    is.close();
    }
    return writer.toString().split("" +
    "");

    }

    http://192.168.1.72/getcategories.php is an address that does exist in a server on my network. My phone is connected to wifi, and when I go to that address in the browser it brings up the correct information. But when this code is ran in my application, it brings up an error: "Permission Denied (maybe missing INTERNET permission)" How can I fix this?

    EDIT: I discovered that it fails at the line "InputStream is = conn.getInputStream();"
     

    Advertisement

  2. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    To let your application use internet you need a permission in your andoridmanifest.xml file: <uses-permission android:name="android.permission.INTERNET" />
    That goes before the <application> tag or after.
     
    MIIISTER NEUGIT likes this.

Share This Page

Loading...