0

I'm new with Java

I'm trying to use TextToSpeech, I have Referenced libraries and this .java code by particular example.

My Main.java:

package model;

public class Main {
   public static void main(String[] args) {
       TextToSpeech tts = new TextToSpeech();
       tts.speak("Hello world", 1.0f, false, false);
   }
}

but when I'm trying to run, I got

Error: Could not find or load main class model.Main

Project files:

enter image description here

  • How are you trying to run? – Vishwaksena Aug 18 '18 at 20:49
  • @Vishwaksena Hello, with Run button in Eclipse IDE –  Aug 18 '18 at 20:55
  • Did you try to right click on the Main class and select the Run option from there? – Vishwaksena Aug 18 '18 at 21:13
  • @Vishwaksena I've clicked to `Main.java` as well as to `model`, but can't find Run option thare. Can you provide any guide, how to do that, please. I guess it not the `Build Path`, not sure –  Aug 18 '18 at 22:28
  • This is a most familiar issue and try to use the troubleshooting steps over here [eclipse-error-could-not-find-or-load-main-class](https://stackoverflow.com/questions/26003352/eclipse-error-could-not-find-or-load-main-class) – Vishwaksena Aug 19 '18 at 01:49
  • @Vishwaksena well parameters was already added, I've edited question with image, but I got same error with run –  Aug 19 '18 at 02:21
  • 1
    What is in the _Problems_ view (the project folder is decorated with a red exclamation mark which means the project cannot be built; you have to fix this first)? – howlger Aug 19 '18 at 08:10
  • @howlger Hello, seems like yes, but I can't figure out what the reason of this. Is there any option to find reason of failure? –  Aug 19 '18 at 11:36
  • All errors and warnings are shown in the [_Problems_ view](https://help.eclipse.org/photon/topic/org.eclipse.platform.doc.user/concepts/cprbview.htm). Copy the error message and added it to your question, please. – howlger Aug 19 '18 at 12:50
  • @howlger I've added error message to question, please check –  Aug 19 '18 at 17:53

1 Answers1

0

The three source files (AudioPlayer.java, Main.java and TextToSpeech.java) are added by mistake as JARs to the build path (source code are included via source folders instead). This prevents Eclipse from compiling the code and therefore the compiled Java class model.Main is missing.

To fix the problem do the following:

  1. In Project > Properties: Java Build Path, in the tab Libraries select the following items:
    • AudioPlayer.java - TTS/src/model
    • TextToSpeech.java - TTS/src/model
    • Main.java - TTS/src/model
  2. Click Remove
  3. Click Apply and Close
howlger
  • 31,050
  • 11
  • 59
  • 99
  • I've edited question, after removing, I got `exception in thread "main" java.lang.Error: Unresolved compilation problem: The declared package "application" does not match the expected package "model" ` –  Aug 19 '18 at 20:49
  • 1
    `AudioPlayer.java` and `TextToSpeech.java` are located in the package `model` but contain the line `package application;`. Either change `package application;` to `package model;` in both files or create a package `application` and move the two files to this package. – howlger Aug 19 '18 at 20:56