ClassNotFoundException in FreeTTS Java program - java

I am new to FreeTTS and this is my first program.The following program simply reads out a string passed.
I am using Linux Mint 32-bit if that matters.But I extracted jsapi.jar on my windows machine a day back.I believe it doesn't matter.
import javax.speech.*;
import java.util.*;
import javax.speech.synthesis.*;
public class Speak
{
String speaktext;
public void dospeak(String speak,String voicename)
{
speaktext=speak;
String voiceName =voicename;
try
{
SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general", Locale.US,null,null);
Synthesizer synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
desc = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = desc.getVoices();
Voice voice = null;
for (int i = 0; i < voices.length; i++)
{
if (voices[i].getName().equals(voiceName))
{
voice = voices[i];
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
System.out.print("Speaking : "+speaktext);
synthesizer.speakPlainText(speaktext, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch (Exception e)
{
String message = " missing speech.properties in " + System.getProperty("user.home") + "\n";
System.out.println(""+e);
System.out.println(message);
}
}
public static void main(String[] args)
{
Speak obj=new Speak();
obj.dospeak("Finally It speaks and speaks and speaks","kevin16");
}
}
I am getting this as a gift.
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/ValidationException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at javax.speech.Central.registerEngineCentral(Central.java:703)
at javax.speech.Central.loadProps(Central.java:775)
at javax.speech.Central.availableSynthesizers(Central.java:651)
at javax.speech.Central.createSynthesizer(Central.java:553)
at Speak.dospeak(Speak.java:16)
at Speak.main(Speak.java:47)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.ValidationException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
What can I do not to accept this gift.
PS
I have added all the 4 archives viz en_us.jar,freetts-jsapi10.jar, jsapi.jar,mbrola.jar

1) Find in which jar this class is usually defined:
com.sun.speech.freetts.ValidationException
2) See if you have the jar
3) See if you have the right version of this jar
(open it, see if the class file is there)
4) See if the jar is in the classpath at runtime

Related

Adding ASM library as a dependancy while compiling from terminal with javac

I am using ASM 5.2 for an example project and I want to compile the project which has as dependacy the ASM library.
The java file i am trying to compile is the following:
import java.io.FileInputStream;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import static org.objectweb.asm.Opcodes.ASM5;
public class Parser2 {
public static void main(final String args[]) throws Exception {
FileInputStream inputFile = new FileInputStream("/src/Test.class");
ClassReader reader = new ClassReader(inputFile);
GraphClass gc = new GraphClass();
reader.accept(gc, 0);
}
}
class GraphClass extends ClassVisitor {
public GraphClass() {
super(ASM5);
}
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
GraphMethod newVisitor = new GraphMethod(name);
return newVisitor;
//return super.visitMethod(access, name, desc, signature,exceptions);
}
}
class GraphMethod extends MethodVisitor{
public String MthName;
public GraphMethod(String name) {
super(ASM5);
MthName = name;
}
public void visitMethodInsn(int opcode, java.lang.String owner, java.lang.String name, java.lang.String descriptor, boolean isInterface) {
System.out.println(owner + "." + MthName + " ===> " + owner + "." + name);
}
}
I compile it with
javac -classpath asm-all-5.2.jar Parser2.java
which creates the class files GraphClass.class, GraphMethod.class and Parser2.class.
Then upon executing the Parser2 the following error comes up.
$ java Parser2
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 7 more
Why does it say it cannot find the ClassVisitor?
java version in use openjdk version "1.8.0_252"

Error caused by java.lang.NoClassDefFoundError and ClassNotFoundException

I am trying to implement a simple code to read the data from the ultrasonic and send it to a server by using Californium. The problem is that when I use debug, it doesn't have any error. However when I export the code to a runable jar file and run it on my raspberry pi, it throws the following errors:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/californium/elements/util/NamedThreadFactory
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:163)
at org.eclipse.californium.core.CoapServer.<init>(CoapServer.java:120)
at iot.main.device.DeviceClient.main(DeviceClient.java:34)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
I am not sure what caused this and how to solve it, any suggestion would be much helpful. Below is the code:
package iot.main.device;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST;
import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CHANGED;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.coap.MediaTypeRegistry;
import org.eclipse.californium.core.server.resources.CoapExchange;
import com.pi4j.io.gpio.*;
public class DeviceClient {
private static GpioPinDigitalOutput sensorTriggerPin ;
private static GpioPinDigitalInput sensorEchoPin ;
final static GpioController gpio = GpioFactory.getInstance();
public static void main(String[] args) {
double ultraVal;
sensorTriggerPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04); // Trigger pin as OUTPUT
sensorEchoPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_05,PinPullResistance.PULL_DOWN); // Echo pin as INPUT
CoapClient client = new CoapClient("coap://localhost/Ultrasonic");
CoapServer server = new CoapServer();
server.add(new UltraResource());
server.start();
while(true){
try {
Thread.sleep(2000);
sensorTriggerPin.high(); // Make trigger pin HIGH
Thread.sleep((long) 0.00001);// Delay for 10 microseconds
sensorTriggerPin.low(); //Make trigger pin LOW
while(sensorEchoPin.isLow()){ //Wait until the ECHO pin gets HIGH
}
long startTime= System.nanoTime(); // Store the surrent time to calculate ECHO pin HIGH time.
while(sensorEchoPin.isHigh()){ //Wait until the ECHO pin gets LOW
}
long endTime= System.nanoTime(); // Store the echo pin HIGH end time to calculate ECHO pin HIGH time.
ultraVal = ((((endTime - startTime)/1e3)/2) / 29.1);
System.out.println("Distance : " + ultraVal + " cm"); //Printing out the distance in cm
Thread.sleep(1000);
CoapResponse response = client.put(Double.toString(ultraVal), MediaTypeRegistry.TEXT_PLAIN);
if (response!=null) {
System.out.println( response.getCode() );
System.out.println( response.getOptions() );
System.out.println( response.getResponseText() );
} else {
System.out.println("Request failed");
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static class UltraResource extends CoapResource {
public String value = "Resource has not changed yet !!!";
public UltraResource() {
super("Ultrasonic");
setObservable(true);
}
#Override
public void handleGET(CoapExchange exchange) {
exchange.respond(value);
}
#Override
public void handlePUT(CoapExchange exchange) {
String payload = exchange.getRequestText();
System.out.println(payload + " cm");
try {
exchange.respond(CHANGED, payload);
value = new String(payload);
changed();
} catch (Exception e) {
e.printStackTrace();
exchange.respond(BAD_REQUEST, "Invalid String");
}
}
}
}
The error states that
Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.util.NamedThreadFactory
This means you are writing code that uses a dependency from Californium. That dependency is within your dev. environment but it is not within the runtime environment of your Raspberry Pi.
Have a look at this other post which may help you. Also this SO site may be better.

java.lang.NoClassDefFoundError: com/google/common/io/NullOutputStream

I have just started to learn NetApp SDK and trying to run the very first example created by NetApp. I am getting the following error and I don't have any idea why there is something related to com/google/common/io/NullOutputStream
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/NullOutputStream
at com.netapp.nmsdk.client.ApiTarget$Encoding$1.createApiInvocation(ApiTarget.java:202)
at com.netapp.nmsdk.client.ApiRunner.createApiInvocation(ApiRunner.java:153)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:131)
at com.netapp.nmsdk.client.ApiRunner.run(ApiRunner.java:105)
at getSystemMode.getSystemMode.main(getSystemMode.java:30)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.NullOutputStream
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
package getSystemMode;
import com.netapp.nmsdk.client.ApiRunner;
import com.netapp.nmsdk.client.ApiTarget;
import com.netapp.nmsdk.client.ApiTarget.TargetType;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionRequest;
import com.netapp.nmsdk.ontap.api.system.SystemGetVersionResponse;
public class getSystemMode {
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("Usage: SystemMode <storage-system> <user> <passwd>");;
System.exit(1);
}
try {
ApiRunner runner = new ApiRunner(ApiTarget.builder()
.withHost(args[0])
.withUserName(args[1])
.withPassword(args[2])
.withTargetType(TargetType.FILER)
.useHttp()
.build());
SystemGetVersionRequest req = new SystemGetVersionRequest();
SystemGetVersionResponse resp = runner.run(req);
if (resp.isClustered() != null && resp.isClustered()) {
System.out.println("The storage system " + args[0] + " is in \"Cluster-Mode\"");
} else {
System.out.println("The storage system " + args[0] + " is in \"7-Mode\"");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
NullOutputStream removed from Guava 15.
Use ByteStreams.nullOutputStream() instead. This class is scheduled to be removed in Guava release 15.0.
You have to look your guava version.
More info;
Guava Version Problem About NullOutputStream

Apache Spark MySQL JavaRDD.foreachPartition - why I getting ClassNotFoundException

I would like to save data from each partition to MySQL Database. For doing that I created Class which implements VoidFunction<> :
public class DatabaseSaveFunction implements VoidFunction<Iterator<String>> {
/**
*
*/
private static final long serialVersionUID = -7039277486852158360L;
public void call(Iterator<String> it) {
Connection connect = null;
PreparedStatement preparedStatement = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://"
+ "xxx.us-west-2.rds.amazonaws.com" + "/"
+ "xxx", "xxx", "xxx");
preparedStatement = connect
.prepareStatement("insert into testdatabase.test values (default, ?)");
while (it.hasNext()) {
String outputElement = it.next();
preparedStatement.setString(1, "" + outputElement.length());
preparedStatement.executeUpdate();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connect.close();
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
And in my main method class I'm calling:
output.foreachPartition(new DatabaseSaveFunction());
I'm getting following error:
15/05/06 15:34:00 WARN scheduler.TaskSetManager: Lost task 0.0 in stage 1.0 (TID 4, ip-172-31-36-44.us-west-2.compute.internal): java.lang.ClassNotFoundException: DatabaseSaveFunction
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
Worker log:
15/05/06 15:34:00 ERROR executor.Executor: Exception in task 1.0 in stage 1.0 (TID 5)
java.lang.ClassNotFoundException: DatabaseSaveFunction
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
Can anybody tell me what I'm doing wrong ? I would be very grateful for that.
Export the external class to jar and add that like sc.addJar("/path/x.jar") where sc is JavaSparkContext in your main. Then you wont get this error. The error is because you spark program is not able to find the class. Moreover in spark 1.3 and greater you can simple use a map options of jdbc and then use load("jdbc", options) to create a data frame and load data from any RDBMS. its really handy. I am not sure if this method works for connecting any RDBMS into spark. Please tell me if you have any other question.

Why driver is still missing?

I am trying to use Java DB for app only storage.
Environment Variables:
CLASSPATH:
%JAVA_HOME%\jre\lib;%DERBY_HOME%\lib\derby.jar
DERBY_HOME:
C:\Program Files\Java\jdk1.7.0_25\db
Path:
%DERBY_HOME%\bin
No changes in eclipse configurations was done and i cannot include it to build path(it somehow will be considered as third party library, which is not allowed)
When i type "sysinfo" in cmd it tells me Db is instaled and list packages and other info.
Code:
public class Main {
private static String dbURL = "jdbc:derby:AssertDB;user=me;password=mine;create=true";
private static Connection con = null;
public static void main(String[] args) {
setDBSystemDir();
createConnection();
CookiesTable pTable = new CookiesTable(con);
try {
pTable.createTable();
pTable.populateTable();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// TODO Auto-generated method stub
// load files
// parse files to tables
// retrive SQL statment
// print result
}
private static void setDBSystemDir() {
// Decide on the db system directory: <userhome>/.addressbook/
String userHomeDir = System.getProperty("user.home", ".");
String systemDir = userHomeDir + "/.asertdb";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
}
private static void createConnection() {
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
// Get a connection
con = DriverManager.getConnection(dbURL);
} catch (Exception except) {
System.out.println("DRIVER DRROOOOOP");
except.printStackTrace();
}
}
}
Exception:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.tuto.p4.Main.createConnection(Main.java:44)
at com.tuto.p4.Main.main(Main.java:13)
Exception in thread "main" java.lang.NullPointerException
at com.tuto.p4.CookiesTable.createTable(CookiesTable.java:29)
at com.tuto.p4.Main.main(Main.java:16)
Refering to the documentation there are two things to do in case you get a java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver if you run the SampleApp.
Configure Embedded Derby
Verify Derby
As you said that you checked sysinfo I would try it with adding derby.jar and derbytools.jar even if the tools are optional.
Or you can compare the SampleApp to your App....
Include derbytools.jar, derbyclient.jar as well.
Try putting System.out.println(System.getProperty("java.class.path"));
before Class.forName(...).newInstance()
The output must contain a valid path to derby.jar.

Categories

Resources