-1

So I am trying to compile a .java file in my vim script but it keeps giving the error "could not find or load main class name.java" while I have put a main class in my .java file`, can someane help me with that? Thanks.

while i have made a file in my script

public class $name {
    public static void main(String[] args) {
"text"
   }
}
5
  • How do you compile it? Commented Dec 28, 2017 at 16:44
  • @jimmij in my script I wrote javac $naam java $naam Commented Dec 28, 2017 at 16:49
  • this question answered before. kindly check stackoverflow.com/questions/18093928/… Commented Dec 28, 2017 at 16:54
  • Im trying out what they are saying but can find it to work, must i use javac/java naam.java or without .java? Commented Dec 28, 2017 at 17:11
  • 2
    What is the relevance of the shell-script and javascript tags to this question? Commented Dec 28, 2017 at 22:50

1 Answer 1

0

If $name expands to the name of your class, the code must be in a file of exactly the same name plus extension .java. The javac commands wants the full file name, including .java, i.e.

javac CoolCode.java

if $name expands to CoolCode. Just "text" as the body will give you a compile error. If you get past this, run the code with

java CoolCode

Then read about classpath and package name and all the more in the javac and java manual: man javac and man java.

2
  • can i ask u another question? Commented Dec 29, 2017 at 8:40
  • No, not me specifically. Just ask another question. Commented Dec 29, 2017 at 15:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.