Java Compile Error (HelloWorldApp); It shows “Erro

2019-07-16 05:59发布

问题:

This question already has an answer here:

  • Java Access Denied 3 answers

I use Windows 7 and recently installed JDK (jdk1.8.0_05). (I've also installed JRE) As I'm new to Java, I complied the Hello World Java code given on Official Java Website:

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

I saved the file as C:\HelloWorldApp.java

And then in command prompt, I typed

javac HelloWorldApp.java

I got the following message:

C:/HelloWorldApp.java:5: error: error while starting HelloWorldApp: C:\HelloWorldApp.class (Access is denied)

class HelloWorldApp{
^
1 error

PS: I even tried making the class public. Also, I've specified PATH variable as C:\Program Files\Java\jdk1.8.0_05\bin

What may be the solution?

回答1:

Add public keyword before the class keyword. That is, change:

class HelloWorldApp {

to

public class HelloWorldApp {

The class that contains main method must be declared as public.



标签: java cmd