-1

Getting error "Exeption in thread "main" java.lang.Error 'Unresolved compilation problem':

at ClassName.main(ProjectName.java:7)

this is just a test program to see how runtimes work

public static void main(String[] args) 

        Runtime runtime = Runtime.getRuntime();

        String[] s = new String[] {"C:\\Window\\SystemApps\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\MicrosoftEdge.exe", "https://youtu.be/dQw4w9WgXcQ"};

        runtime.exec(s);

    }
rioV8
  • 24,506
  • 3
  • 32
  • 49
sixten
  • 21
  • 1
  • 5

1 Answers1

0

Runtime.exec(String) throws IOException and you don't catch it. Thus your program does not compile.

try {
    runtime.exec(s);
} catch (IOException e) {
    e.printStackTrace();
}

But the "correct" way to open a browser from a Java would be Desktop.browse(URI) like

try {
    Desktop.getDesktop().browse(new URI("https://youtu.be/dQw4w9WgXcQ"));
} catch (Exception e) {
    e.printStackTrace();
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249