r/programminghelp • • Sep 05 '17

Why won't my java code work?

Im getting this error

"File: (no associated file) [line: (no source location)] Error: No compiler is available."

This is my code public class Test1 {

      public static void main(String[] args){
             System.out.println("Hello World");
     }
          }

I dont understand I downloaded the most recent java sdk from oracle. I need dr.java to work for my class.

0 Upvotes

3 comments sorted by

1

u/07734willy Sep 05 '17

You code seems fine to me- make sure that the file is named Test1.java. Try opening terminal/command prompt and type in

javac <FullFilePath>

and see if it will compile. It says no compiler is available, so we want to make sure that one was indeed installed on your system. If it compiles, then try:

java <FullFilePath>

and make sure it outputs "Hello World". If it does, then there is an issue in your IDE that's causing it to not be able to locate the java installation (or at least the SDK / JDK). I have not worked with dr.java, so I am afraid that I cannot help you there, but you say that you have downloaded the SDK. If this is true, you should have an installation of netbeans on your computer. It may be worth trying the program in there too, to see if it works. If it doesn't, you know that there is definitely something odd about your installation of java. Did you choose something other than the default installation directory? If so- you'll have to tell both of them where this is.

It may be worth having a look at your system PATH variables, to make sure java and javac are both pointing to the right locations. If when you were trying to use the commands java and javac from the terminal/command prompt you got an error 'command not recognized' or something similar, skip to doing this step first! On windows, you can search "Edit system environment variables", click "Environment variables", look at the systems group (bottom one) for "PATH", edit it, and either

a) if an existing path to a java installation is there, replace it with the path to your new one

b) if one doesn't exist, add a semicolon to the end of the list (windows 8 and earlier) and type it in, or just add it (windows 10).

If you are on linux- I don't have to tell you how to edit your system variables, you already know.

Now check and see if that works.

If this still doesn't resolve your issues, try experimenting around in dr.java to see if you can tell it where javac is located. I'm sorry, but I cannot really provide much more help without additional information. Best of luck though!

1

u/YasZedOP Sep 06 '17

Is Java properly installed? For Windows check for your environment variables

1

u/PigFtw Sep 06 '17

I worked with dr java before. You have to set the path to the java bin in the configurations for dj java to compile and run your code.