0
votes

MAC OSX

I have the java source file A.java in "$HOME/Documents/personal_documents/java".

class A
{
 public static void main(String args[])
 {

 }
}

Executed following commands:-

  1. cd $HOME/Documents/personal_documents/java
  2. javac A.java ('Got successfully executed')
  3. java A ('Threw the error': Error: Could not find or load main class A , Caused by: java.lang.ClassNotFoundException: A)

Troubleshooting I did on my part:-

  1. /usr/libexec/java_home

    /Users/rishabshinghal/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home

  2. Tried setting JAVA_HOME, PATH env variables explicitly.

    export PATH=$PATH:$HOME/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home/bin

    export JAVA_HOME=$(/usr/libexec/java_home)

  3. Tried executing javac, java using absolute paths

    $HOME/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home/bin/javac A.java

    $HOME/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home/bin/java A

  4. Also tried setting classpath explicitly even though I am in the same directory as class file.

    javac A.java

    java -cp . A

Please help me in this. I spent lot of time in troubleshooting this but didn't get any breakthrough.

1
Are you sure there is not package defined in A.java file?VeryNiceArgumentException
No, there is no package defined inside A.javaprat

1 Answers

-2
votes

public static void main(String[]Args) try this, i hope it helps