0

No matter what edits I make, I keep getting this output;

C:\Program Files\Java\jdk1.7.0_67\bin>javac JavaVersionDisplayApplet.java
JavaVersionDisplayApplet.java:4: error: error while writing JavaVersionDisplayAp
plet: JavaVersionDisplayApplet.class (Access is denied)
public class JavaVersionDisplayApplet extends Applet {
       ^
1 error

The code I'm using is for a JavaCheckVersion;

import java.applet.*;
import java.awt.*;

public class JavaVersionDisplayApplet extends Applet { 
   private Label m_labVersionVendor; 

   public JavaVersionDisplayApplet()  { 
     Color colFrameBackground = Color.white;
     this.setBackground(colFrameBackground);
     m_labVersionVendor = new Label (" You are running Java Version: " +
                                    System.getProperty("java.version") +
                                    " from " + 
                                    System.getProperty("java.vendor"));
     this.add(m_labVersionVendor);
   }

}

Does anyone see anything wrong here?

5
  • It sounds like you don't have write permissions in the relevant place. Commented Oct 11, 2014 at 18:40
  • This is my first project in Java, so I'm not entirely sure how to modify that. The line in question seems to be; public class JavaVersionDisplayApplet extends Applet { Commented Oct 11, 2014 at 18:41
  • Nothing to do with Java. You just need to figure out why you can't write to whatever directory it's trying to generate the output in. Commented Oct 11, 2014 at 18:42
  • 1
    Generally you dont want to keep source files in the JDKs bin directory Commented Oct 11, 2014 at 18:43
  • You know what, its probably because I'm compiling from /jdk/bin/ as a workaround because javac wouldn't navigate to the original directory. Commented Oct 11, 2014 at 18:44

2 Answers 2

1

The problem is not related to your code, but rather to the fact that you are trying to compile it while your current directory is C:\Program Files\Java\jdk1.7.0_67\bin. You probably don't have writing permissions in that directory. Since the action of compiling a class creates a .class file, the compiler cannot complete the compilation.

Change directory to some place where you are allowed to write, and compile again.

Sign up to request clarification or add additional context in comments.

2 Comments

That makes a lot of sense, but that brings me to another problem. I'm compiling within jdk/bin/ because I would receive a "not found" error every time I'd try compiling from desktop/development folder/
@Autonomous Take a look at Oracle's explanation of PATH and CLASSPATH.
0

Ran CMD as admin, & moved the Java file to /Desktop/Java/ and was successful. Thanks everyone for helping me resolve this!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.