Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed regarding jsapi  RSS feed

 
krish arya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends
I am new to jsapi
When i am trying to run the hello world program as given below, it throws a null-pointer exception at the line containing synth.allocate();



import javax.speech.*;
import javax.speech.synthesis.*;
import java.util.Locale;

public class HelloWorld {

public static void main(String args[]) {
try {


// Create a synthesizer for English
Synthesizer synth = Central.createSynthesizer(null);
//new SynthesizerModeDesc(Locale.ENGLISH));


// Get it ready to speak
synth.allocate();
synth.resume();

// Speak the "Hello world" string
synth.speakPlainText("Hello, world!", null);

// Wait till speaking is done
synth.waitEngineState(Synthesizer.QUEUE_EMPTY);

// Clean up
synth.deallocate();
} catch (Exception e) {
System.out.println("Exception occured :"+e+"\n");
e.printStackTrace();
}
}
}


I am not able to resolve it.
Please help me out.......
It seems that there is some problem with classpath but i am not able to correct it.
Please help.
Thanks in advance................
 
Rob Spoor
Sheriff
Posts: 21047
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags. It will make your code so much easier to read.

Now either synth is null, or there is something wrong inside synth.allocate(). My guess is the former; Central.createSynthesizer(null) probably returns null. That's what the API says:

My guess is that this will always happen if you provide a null EngineModeDesc. Why don't you create one and use it? You already have the code for it, you just commented it out. Why?
 
krish arya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply
but that is not the case.


I commented that line because that to had no effect on the exception that is being thrown.

Any way i found out what the problem was.
The problem was with the classpath after setting up correctly,the program is executing correctly
but no sound is being produced.

When i tried other demo codes, it worked correctly.
Please help
 
krish arya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply
but that is not the case.


I commented that line because that to had no effect on the exception that is being thrown.

Any way i found out what the problem was.
The problem was with the classpath after setting up correctly,the program is executing correctly
but no sound is being produced.

When i tried other demo codes, it worked correctly.
Please help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!