Cannot determine current directory

Solution 1:

I saw the same error when I was trying to call java -version inside a directory, which I already had deleted from another terminal session. Of course in that case java could not determine the current working directory, simply because it didn't exist.

Solution 2:

Solution: cd to another directory and run that command again, that works for me.

See explanation here: https://bugs.openjdk.java.net/browse/JDK-8186434

Solution 3:

In Fedora 21, I tried calling the "java -version" after an uninstall and it gave the above error. Close all the terminals and open them again and try.

Should work.

Solution 4:

I was getting the same error message, but I'm not sure if it was for the same reason as I don't use Netbeans. I use my terminal and compile with ant.

I cd'd to a directory to run a javafile.class file. The file I want to run is part of a bigger package. The directory structure of the package looked something like this: a/b/c/javafile.class. The a, b, and c directories are all part of a larger package.

To run my javafile.class, I cd'd into a and ran the file from there: java b/c/javafile. After I made some changes and recompiled with my ant script, the directory I was in had been deleted and remade by ant. So, when I ran javafile.class again, I got the error you're getting.

I fixed my problem by cding out of the directories that are deleted and remade by ant and then running my javafile.class again.

Solution 5:

maybe you did not config java environment on your workstation correctly

the following configurations were what I did in my mac

vi ~/.bash_profile

and add those in it

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
PATH=$JAVA_HOME/bin:$PATH:.
CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export JAVA_HOME
export PATH
export CLASSPATH

replace

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

with your jdk version and then run

source ~/.bash_profile

to use these config immediately then you can check by

java -version