0

Hello i have this code that its supposed to update values in mysql, but the OutputStream ops is making my app crash. I have it run in AsyncTask but still makes error.

try {
            URL url = new URL(connstring);
            HttpURLConnection http = (HttpURLConnection) url.openConnection();

            http.setRequestMethod("POST");
            http.setDoInput(true);
            http.setDoOutput(true);

            OutputStream ops = http.getOutputStream(); //error occurs here

            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(http.getOutputStream(), "UTF-8"));
            data = URLEncoder.encode("visible", "UTF-8") + "=" + URLEncoder.encode(visible, "UTF-8")
                    + "&&" + URLEncoder.encode("visible", "UTF-8") + "=" + URLEncoder.encode(option, "UTF-8");
            writer.write(data);
            writer.flush();
            writer.close();
            ops.close();
           
        } catch (MalformedURLException ex) {
            result = ex.getMessage();
            
        } catch (IOException e) {
            result = e.getMessage();
            
        }

This is the error i get:

java.lang.SecurityException: Permission denied (missing INTERNET permission?)
  • Please post the error including stacktrace or at least mark the line in your posted code where the error occurs. – Robert Jul 13 '22 at 16:12
  • @Robert i got now the error and is `java.lang.SecurityException: Permission denied (missing INTERNET permission?)` –  Jul 13 '22 at 16:12
  • @Robert also made a comment on which line of the code happens the error –  Jul 13 '22 at 16:13
  • Please first search for the error message before making a new post, then you will quickly end up for example here: https://stackoverflow.com/questions/17360924/securityexception-permission-denied-missing-internet-permission and this answer: https://stackoverflow.com/a/35161388/150978 – Robert Jul 13 '22 at 16:22

0 Answers0