1. Check out our companion app, Forums for Android! Download from Google Play

What is wrong with this code?

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

  1. MIIISTER NEUGIT

    Thread Starter
    15

    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 Well-Known Member
    53

    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...