I am trying to read a N-Triples (.nt) DBpedia file with NxParser, but I had the following error, and I don't know what to do.
Exception in thread "main" java.lang.NoClassDefFoundError: org/semanticweb/yars/nx/parser/NxParser$1
at org.semanticweb.yars.nx.parser.NxParser.stringItFromBufferedReader(Unknown Source)
at org.semanticweb.yars.nx.parser.NxParser.<init>(Unknown Source)
at org.semanticweb.yars.nx.parser.NxParser.<init>(Unknown Source)
at SentencesMatching_prova.main(SentencesMatching_prova.java:29)
Caused by: java.lang.ClassNotFoundException: org.semanticweb.yars.nx.parser.NxParser$1
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 4 more
The source code of the script is:
import java.io.*;
import org.semanticweb.yars.nx.parser.*;
public class SentencesMatching_prova {
public static void main(String[] args) {
try {
String relationFileName = "../zzz-trash/revisions_en.nt";
FileInputStream is = new FileInputStream(relationFileName);
NxParser nxp = new NxParser(is);
while (nxp.hasNext()) {
// do stuff
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
}
}
Related
While using XSSFWorkbook getting below exception, added org.apache.poi dependancy
my code is as below, it prints projDir and throws exception after that as mentioned below
public class ExcelUtils {
public static void main(String []args){
getRowCount();
}
public static void getRowCount(){
try {
String projDir =System.getProperty("user.dir");
System.out.println(projDir);
String excelPath = "./data/TestData.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook(excelPath);
} catch (Exception exp) {
System.out.println(exp.getMessage());
System.out.println(exp.getCause());
exp.printStackTrace();
}
}
}
And below is full log track
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:98)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
at org.apache.poi.POIXMLDocument.openPackage(POIXMLDocument.java:62)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:188)
at utils.ExcelUtils.getRowCount(ExcelUtils.java:24)
at utils.ExcelUtils.main(ExcelUtils.java:11)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
I know there are similar questions out there but none of those solutions work for my case.
I tried to execute a Java file using Windows PowerShell.
This is what I have for Java file:
public class Demo1 {
public static void main (String arg[]){
System.out.println("DEMO1 START RUNNING");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Unable to process");
}
System.out.println("DEMO1 JAVA COMPLETED.");
}
}
For easy compilation, I have copies of Demo1.java, Demo1.jar, and Demo1.class in the desktop directory.
for powershell command, I have tried:
1st attempt:
C:..\Desktop> java Demo1.java
2nd attempt:
C:..\Desktop> java -class Demo1.class
3rd attempt:
C:..\Desktop> java -jar Demo1.jar
All the above attempt return this error:
PS C:\Users\b003485\Desktop> java .\Demo1.java
Exception in thread "main" java.lang.NoClassDefFoundError: /\Demo1/java
Caused by: java.lang.ClassNotFoundException: .\Demo1.java
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: .\Demo1.java. Program will exit.
In an android app, having:
public class Pars extends Activity{
public Document docout(){
InputStream is = getResources().openRawResource(R.raw.talechap01);
Document docout = null;
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = domFactory.newDocumentBuilder();
docout = builder.parse(is);
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return docout;
}
and
public class Manager {
public static String getStory(String spage, Document docs) {
XPathExpression expr;
XPath xpath = XPathFactory.newInstance().newXPath();
Object result = null;
String num = spage;
String par = null;
try {
expr = xpath.compile("//decision"+num+"/p//text()");
result = expr.evaluate(docs, XPathConstants.NODESET);
}
catch (XPathExpressionException e) {
e.printStackTrace();
}
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
par = nodes.item(i).getNodeValue();
System.out.println(par);
}
return par;
}
}
Now I want to test the code.
public class Test {
public static void main(String[] args) {
try {Pars p = new Pars();
Document doc = p.docout();
System.out.println(Manager.getStory("000", doc));
}catch (Exception e){
e.printStackTrace();
}
}
}
I run "Test" as a java application and I get:
Exception in thread "main" java.lang.NoClassDefFoundError:
android/app/Activity at java.lang.ClassLoader.defineClass1(Native
Method) at java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
com.stack.over.Test.main(Test.java:11) Caused by:
java.lang.ClassNotFoundException: android.app.Activity at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 13 more
I tried to find how to fix it but cannot achieve it.
I have this answer from another question but I'm kind of noob yet and can't figure it out how to fix it.
You have defined your Pars class as extending the class Activity. The
error you are seeing is telling you that the class
android.app.Activity is not available on the classpath. Maybe you need
to check which libraries you import. – adamretter Mar 5 at 10:01
Thanks all.
The error is that you're trying to run a program that references Android classes (android.app.Activity) as a regular Java program that doesn't have Android runtime libraries in its classpath.
You should run Android apps as Android apps (on an emulator or a device) and regular Java programs as regular Java programs and not mix the two. Activity is Android; main() method is regular Java.
To learn Android app development, you can start with the developer.android.com getting started documentation.
The error message says it all. You are writing Android now. Trying to write a main method doesn't make any more sense in Android than it would if you were writing a webapp that runs in Tomcat. You are going to need to step back and read up on how Android works.
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
I wan't to try to load a class and if this class can't be loaded to continue my program.
protected void checkClass(){
classChecked = false;
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> compiledClass = cl.loadClass(sTestclass); // << EXCEPTIOn lINE
cRun = compiledClass;
classChecked = true;
} catch (Exception e) {
e.printStackTrace();
System.err.println("- Testclass not found!");
System.err.println("- Make sure you typed the package name\n and the Class name correctly!");
}
}
But instead the whole progam exits with this:
Exception in thread "main" java.lang.NoClassDefFoundError: data/testcases/comman
do/ctest (wrong name: data/testcases/commando/CTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
1)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at cmd.TwCmd.checkClass(TwCmd.java:214)
at cmd.TwCmd.askForTestcase(TwCmd.java:107)
at cmd.TwCmd.anotherTestcase(TwCmd.java:146)
at cmd.TwCmd.executeInteractiveTw(TwCmd.java:85)
at cmd.TwCmd.runThrough(TwCmd.java:60)
at cmd.TwCmd.main(TwCmd.java:260)
I already surrounded it with Try/Catch but still the whole program exits on this error?
NoClassDefFoundError is not an Exception, it derives from Error.
Try catching Throwable if you want to catch them all.
You see an Error, not an Exception. Catch the NoClassDefFoundError and you should be able handle it in a catch block and continue.
(java.lang.NoClassDefFoundError is not a subclass of java.lang.Exception)