0

I am trying to run a Java program on cmd but it throws

Error: Could not find or load main class sample2

sample2.java is the file name and I have no idea. I am using a text editor only. sample2.java Code

class MyFirstApp {
    public static void main(String[] args) {
        System.out.println("I rule");
        System.out.println("The world");
    }
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Can you post the code from `sample2.java`? (Btw: It is better to call it `Sample2`). Maybe this helps you [Compile and run your first Java program](http://stackoverflow.com/documentation/java/84/compile-and-run-your-first-java-program#t=201608101228263496349) – CloudPotato Aug 10 '16 at 12:27
  • `.java` files are uncompiled, you might want to start the `.class` files. – SomeJavaGuy Aug 10 '16 at 12:27
  • What commands are you using to run the code? What is your pwd? Is the file in your pwd? Did you compile it? Some more information would help. – Isabel Inc Aug 10 '16 at 12:27
  • where is the file located, go to that path and then give a try for executing the programm – Rishal Aug 10 '16 at 12:29
  • Okay to answer your questions. here are the codes for sample2.java ,.. class MyFirstApp { public static void main(String[] args) { System.out.println("I rule"); System.out.println("The world"); } } i used javac sample2.java to compile and it identified the errors which i later debugged it and on using java sample2.java it brought the error i have posted @Blobonat – Sospeter Mong'are Aug 10 '16 at 12:32
  • @sospetermong'are You have to run `java sample2` without `.java` – CloudPotato Aug 10 '16 at 12:39
  • @Blobonat it brings the same error – Sospeter Mong'are Aug 10 '16 at 12:43
  • @sospetermong'are There could be many reasons for that. For example your Classpath is wrong. Maybe you find the solution here: [What does “Could not find or load main class” mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – CloudPotato Aug 10 '16 at 12:48
  • i finaly got the answer,.. i was to wrote the class name i used inside the code that is MyFirstApp – Sospeter Mong'are Aug 10 '16 at 13:06

0 Answers0