0

I'm a beginner trying to learn to program in Java. I'm using the book Java All In One for Dummies. The book has me using Textpad to write and compile the code. I've got the following simple program:

public class HelloApp  {

    public static void main(String[] args)  {

        printHello("World");
        }

    public static void printHello(String greetee) {

        System.out.println("Hello " + greetee);


     }
}

I saved the files for the java application in at the following path. D:\program files\java. When I compile the app with the Textpad compiler, it compiles without any errors. I have the files saved in the following folder: D:\program files\java. When I try to run the app from the Run Java Application command in Textpad, it gives me the error message "Error: Could not find or load main class HelloApp.java". When I run the app from the command prompt using the java HelloApp.java, it runs fine displaying "Hello World" Why does it work when I run it using the java HelloApp.java command which is what I assume the "run java application" command in Textpad does, and not work using the command in Textpad? What am I doing wrong?

I tried resaving and recompiling the application. Then I ran it directly from the command prompt. It worked when running directly from the command prompt but it won't work when trying to run from the "Run Java Application" command in Textpad.

I assumed it would work as it seems like I'm doing the exact same thing from Textpad as I am from using the java HelloApp.java command at the windows command prompt.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
  • I'm not quite following your explanation of what you tried, but you need to be in the `D:\program files\java` directory when you run `java HelloApp.java`. If you're not in that directory already, use `cd` to get there. – Dawood ibn Kareem Dec 14 '22 at 03:14
  • This may be a configuration issue in the TextPad: Configure -> Preference -> Run Java Application . – prasad_ Dec 14 '22 at 04:37

0 Answers0