how can solve java exception error [duplicate] - java

This question already has answers here:
Why am I getting a NoClassDefFoundError in Java?
(31 answers)
Closed 4 years ago.
I,m working in eclipse with java language but i have error when write the
POS standford api code for tagging the text. plz, can any one help me , the
error as follow
"Exception in thread "main" java.lang.NoClassDefFoundError:
org/slf4j/LoggerFactory at edu.stanford.nlp.pipeline.StanfordCoreNLP.
(StanfordCore.<clinit>(StanfordCoreNLP.java:99)
at tweetfileanalysis.TweetPOS.tweettag(TweetPOS.java:23)
at tweetfileanalysis.ReadJson.readJsonf(ReadJson.java:288)
at tweetfileanalysis.Mainclass.main(Mainclass.java:17)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown
Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
i put all libraries by using configure build path so what can i do to solve the error the class code as follow:
package tweetfileanalysis;
import edu.stanford.nlp.ie.util.RelationTriple;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.naturalli.NaturalLogicAnnotations;
import edu.stanford.nlp.util.CoreMap;
import java.util.Collection;
import java.util.Properties;
public class TweetPOS{
public TweetPOS()
{}
public static void tweettag(String tweet)
{
// Create the Stanford CoreNLP pipeline
Properties props = new Properties();
props.getProperty("annotators",
"tokenize,ssplit,pos,lemma,depparse,natlog,openie");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// Annotate an example document.
Annotation doc = new Annotation("Obama was born in Hawaii. He is our
president.");
pipeline.annotate(doc);
System.out.println("fhfbg");
// Loop over sentences in the document
for (CoreMap sentence :
doc.get(CoreAnnotations.SentencesAnnotation.class)) {
// Get the OpenIE triples for the sentence
Collection<RelationTriple> triples =
sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
// Print the triples
System.out.println("uuuuuuuuuuuuuuuuuuu");
for (RelationTriple triple : triples) {
System.out.println(triple.confidence + "\t" +
triple.subjectLemmaGloss() + "\t" +
triple.relationLemmaGloss() + "\t" +
triple.objectLemmaGloss());
}
}
}
}

Download slf4j.jar here and config your build path.

Related

I'm getting an error in java using eclipse after running the following code for weather API?

**
I'm trying to run the following code which has a weather api an is supposed to tell a weather of a selected location but i'm getting a following error?
**
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at net.aksingh.owmjapis.core.OWM.<init>(OWM.kt)
at myCbot.main(myCbot.java:11)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
** im getting error fro the following java code **
import net.aksingh.owmjapis.core.OWM;
import net.aksingh.owmjapis.api.APIException;
import net.aksingh.owmjapis.model.CurrentWeather;
public class myCbot {
public static void main(String[] args) throws APIException {
// declaring object of "OWM" class
OWM owm = new OWM("some-api-key");
// getting current weather data for the "London" city
CurrentWeather cwd = owm.currentWeatherByCityName("London");
// printing city name from the retrieved data
System.out.println("City: " + cwd.getCityName());
// printing the max./min. temperature
System.out.println(
"Temperature: " + cwd.getMainData().getTempMax() + "/" + cwd.getMainData().getTempMin() + "\'K");
}
}

How to run generated frege java code on jvm?

hello world in haskell frege :
hello.fr :
module Hello where
main args = do
putStrLn "Hello, World!"
This code generates hello.java :
/*
Source code is in UTF-8 encoding. The following symbols may appear, among others:
α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω « • ¦ » ∀ ∃ ∷ … → ← fi fl ƒ
If you can't read this, you're out of luck. This code was generated with the frege compiler version 3.24.80
from hello.fr Do not edit this file! Instead, edit the source file and recompile.
*/
import frege.run8.Func;
import frege.run8.Lazy;
import frege.run8.Thunk;
import frege.run.Kind;
import frege.run.RunTM;
import frege.runtime.Meta;
import frege.runtime.Phantom.RealWorld;
import frege.Prelude;
import frege.control.Category;
import frege.control.Semigroupoid;
import frege.java.IO;
import frege.java.Lang;
import frege.java.Util;
import frege.java.util.Regex;
import frege.prelude.Maybe;
import frege.prelude.PreludeArrays;
import frege.prelude.PreludeBase;
import frege.prelude.PreludeIO;
import frege.prelude.PreludeList;
import frege.prelude.PreludeMonad;
import frege.prelude.PreludeText;
#SuppressWarnings("unused")
#Meta.FregePackage(
source="hello.fr", time=1470398249962L, jmajor=1, jminor=8,
imps={
"frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase", "frege.prelude.PreludeIO",
"frege.prelude.PreludeList", "frege.prelude.PreludeMonad", "frege.prelude.PreludeText", "frege.java.util.Regex"
},
nmss={"Prelude", "PreludeArrays", "PreludeBase", "PreludeIO", "PreludeList", "PreludeMonad", "PreludeText", "Regexp"},
symas={}, symcs={}, symis={}, symts={},
symvs={#Meta.SymV(offset=20, name=#Meta.QName(pack="Hello", base="main"), stri="s(u)", sig=1, depth=1, rkind=49)},
symls={},
taus={
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="[]")}),
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="StringJ")}),
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="Char")}),
#Meta.Tau(kind=0, suba=1, subb=2), #Meta.Tau(kind=0, suba=0, subb=3),
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="ST")}),
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="RealWorld")}),
#Meta.Tau(kind=0, suba=5, subb=6),
#Meta.Tau(kind=2, suba=0, tcon={#Meta.QName(kind=0, pack="frege.prelude.PreludeBase", base="()")}),
#Meta.Tau(kind=0, suba=7, subb=8)
},
rhos={#Meta.Rho(rhofun=false, rhotau=4), #Meta.Rho(rhofun=false, rhotau=9), #Meta.Rho(sigma=0, rhotau=1)},
sigmas={#Meta.Sigma(rho=0), #Meta.Sigma(rho=2)}, exprs={#Meta.Expr()}
)
final public class Hello {
final public static Func.U<RealWorld, Short> $main(final Lazy<PreludeBase.TList<String/*<Character>*/>> arg$1) {
return Prelude.putStrLn("Hello, World!");
}
public static void main(final java.lang.String[] argv) {
try {
frege.run.RunTM.argv = argv;
PreludeBase.TST.<Short>performUnsafe($main
(Thunk.lazy(PreludeArrays.IListSource_JArray.<String/*<Character>*/>toList(argv)))
).call();
frege.runtime.Runtime.stdout.get().close();
frege.runtime.Runtime.stderr.get().close();
} finally { frege.run.Concurrent.shutDownIfExists(); }
}
}
I then compile the generated java code with no error :
javac -cp frege3.jar build/Hello.class
I then attempt to run the code :
cd build
java Hello
But this returns an error :
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: frege/run8/Lazy
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: frege.run8.Lazy
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)
... 7 more
How to run the generated frege java code on jvm ?
I'm using java8
You need to add frege3.jar in your classpath also when you launch the command, so try this:
java -cp .:frege3.jar Hello
Assuming that frege3.jar and Hello.class are both in the current directory
You don't need an extra javac compilation, this is automatically done by the frege compiler (unless suppressed by a flag).
Yes, there is a getting started document here: https://github.com/Frege/frege/wiki/Getting-Started

Scala: for loop: iterating over a a directory stream

Update:
I have written the following updated code after inputs from Scala experts here.
Here below is the updated code.
The code compiles, but on "run" throws an IllegalStateException: I posted the error stacktrace after the code listing:
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.FileVisitOption
import java.nio.file.FileVisitResult
import java.nio.file.FileVisitor
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.attribute.BasicFileAttributes
import java.util.EnumSet
import java.nio.file.{DirectoryStream,DirectoryIteratorException}
import scala.collection.JavaConversions._
class TestFVis(val searchPath: Path) extends FileVisitor[Path] {
//Here I provide implementations for postVisitDirectory,
//preVisitDirectory, visitFile, and visitFileFailed
}
object Main {
def main(args: Array[String]) {
val searchFileOrFolder: Path = Paths.get("C://my_dir")
println("The Path object is: " + searchFileOrFolder)
var testFileVisitorTop = new TestFVis(searchFileOrFolder)
println("Our top level FileVisitor is: " + testFileVisitorTop)
val opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS)
val rootDirsIterable: Iterable[Path] = FileSystems.getDefault.getRootDirectories //returns the default filesystem
// and then returns an Iterable[Path] to iterate over the paths of the root directories
var dirStream:Option[DirectoryStream[Path]] = None
for(rootDir <- rootDirsIterable) {
println("in the Outer For")
dirStream= Some(Files.newDirectoryStream(searchFileOrFolder))
def dstream = dirStream.get
val streamIter = dstream.iterator().filter((path) => {
Files.isRegularFile(path)
})
for( dirStreamUnwrapped <- dirStream;(filePath:Path) <- dirStreamUnwrapped) {
//for( (filePath: DirectoryStream[Path]) <- dirStream) {
val tempPath = Files.walkFileTree(filePath, testFileVisitorTop)
//val tempPath = Files.walkFileTree(fileOrDir,opts,Integer.MAX_VALUE,testFileVisitorTop)
println("current path is: " + tempPath)
if (!testFileVisitorTop.found) {
println("The file or folder " + searchFileOrFolder+ " was not found!")
}
}
}
}
}
However for historical context here is the compile error I got at first:
[error] found : java.nio.file.Path => Unit
[error] required: java.nio.file.DirectoryStream[java.nio.file.Path] => ?
[error] for((filePath:Path) <- dirStream) {
--
After changing the code:
The code compiles with no errors, but I get an IllegalStateException on sbt 'run'\
> run
ur top level FileVisitor is C:\my_dir
Our top level FileVisitor is: com.me.ds.TestFileVisitor
#5564baf6
in the Outer For
[error] (run-main-0) java.lang.IllegalStateException: Iterator already obtained
java.lang.IllegalStateException: Iterator already obtained
at sun.nio.fs.WindowsDirectoryStream.iterator(WindowsDirectoryStream.jav
a:117)
at scala.collection.convert.Wrappers$JIterableWrapper.iterator(Wrappers.
scala:54)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.s
cala:777)
at com.me.ds.Main$$anonfun$main$1$$anonfun$appl
y$1.apply(SampleFileVis.scala:76)
at com.me.ds.Main$$anonfun$main$1$$anonfun$appl
y$1.apply(AFileVisitor.scala:76)
at scala.Option.foreach(Option.scala:256)
at **com.me.ds.Main$$anonfun$main$1.apply(SampleFileVisitor.scala:76)**
at com.me.ds.Main$$anonfun$main$1.apply(AFileVi
sitor.scala:68)
at scala.collection.Iterator$class.foreach(Iterator.scala:743)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1195)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at com.me.ds.Main$.main(SampleFileVis.scala:68)
at com.me.ds.Main.main(SampleFileVis.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 0 s, completed Mar 24, 2015 7:32:38 AM
>
=-------------
I am going out and investigating the error on my own also. If someone can point me in the right direction here that would make my code compile and run, I would have accomplished my goal here.
thanks
All you are doing with the first for is unwrapping the Option, which cannot be cast to a Path. You just need to take your unwrapped object and use it in the next part:
for(dirStreamUnwrapped <- dirStream;
(filePath:Path) <- dirStreamUnwrapped) {
val tempPath = Files.walkFileTree(filePath, testFVis)
}
object needs to be lowercase.
dirStream needs to be preceded by val.
you have too many } at the end.
you have new TestFileVisitor but you meant new TestFVis.
dirStream has type: Some[DirectoryStream[Path]], which means that you need (filePath: DirectoryStream[Path]) <- dirStream

java.lang.UnsatisfiedLinkError:Can't find dependent libraries [duplicate]

This question already has answers here:
How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
(18 answers)
Closed 8 years ago.
I am new to lp solve.
I am trying to run the following code and getting the following error:
package package1;
/**
* Created by ANJANEY on 6/13/2014.
*/
import lpsolve.*;
public class Demo {
public static void main(String[] args) {
try {
// Create a problem with 4 variables and 0 constraints
LpSolve solver = LpSolve.makeLp(0, 4);
// add constraints
solver.strAddConstraint("3 2 2 1", LpSolve.LE, 4);
solver.strAddConstraint("0 4 3 1", LpSolve.GE, 3);
// set objective function
solver.strSetObjFn("2 3 -2 3");
// solve the problem
solver.solve();
// print solution
System.out.println("Value of objective function: " + solver.getObjective());
double[] var = solver.getPtrVariables();
for (int i = 0; i < var.length; i++) {
System.out.println("Value of var[" + i + "] = " + var[i]);
}
// delete the problem and free memory
solver.deleteLp();
}
catch (LpSolveException e) {
e.printStackTrace();
}
}
}
Error:
Exception in thread "main" java.lang.UnsatisfiedLinkError:E:\HIVEMINDS\ThirdProject\lp_solve_5.5.2.0_dev_win64\lpsolve55j.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1872)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1087)
at lpsolve.LpSolve.<clinit>(LpSolve.java:275)
at package1.Demo.main(Demo.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Are you sure you load correct libraries in other classes with System.loadlibrary?
If yes, I think quick solution can be putting all libraries in a folder that exists in os's PATH (for instance system32, windows) This has worked for me everytime if there is no any other issue

Exception while using createOntologyModel

package tutorial;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class Jena {
/**
* #param args
* #throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStream in = new FileInputStream(new File("E:\\Applications\\workspace-protoge\\periodic.owl"));
OntModel model2 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM);
model2.read( in, null );
//prints out the RDF/XML structure
in.close();
System.out.println(" ");
// Create a new query
String queryString =
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+
"select ?uri "+
"where { "+
"?uri rdfs:subClassOf <http://www.co-ode.org/roberts/pto.owl#Charge> "+
"} \n ";
Query query = QueryFactory.create(queryString);
System.out.println("----------------------");
System.out.println("Query Result Sheet");
System.out.println("----------------------");
System.out.println("Direct&Indirect Descendants (model1)");
System.out.println("-------------------");
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, model2);
com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
}
}
On running the above code,i get the following warning.
I cannot understand why
WARN [main] (OntDocumentManager.java:1078) - An error occurred while attempting to read from http://www.cs.man.ac.uk/~stevensr/ontology/units.owl. Msg was 'java.net.SocketException: Permission denied: connect'.
com.hp.hpl.jena.shared.JenaException: java.net.SocketException: Permission denied: connect
at com.hp.hpl.jena.rdf.arp.JenaReader.read(JenaReader.java:91)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:187)
at com.hp.hpl.jena.util.FileManager.readModelWorker(FileManager.java:367)
at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:335)
at com.hp.hpl.jena.util.FileManager.readModel(FileManager.java:319)
at com.hp.hpl.jena.ontology.OntDocumentManager.read(OntDocumentManager.java:1064)
at com.hp.hpl.jena.ontology.OntDocumentManager$1.readModel(OntDocumentManager.java:1034)
at com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl.getModel(ModelMakerImpl.java:78)
at com.hp.hpl.jena.ontology.OntDocumentManager.fetchLoadedImportModel(OntDocumentManager.java:1031)
at com.hp.hpl.jena.ontology.OntDocumentManager.fetchPossiblyCachedImportModel(OntDocumentManager.java:1004)
at com.hp.hpl.jena.ontology.OntDocumentManager.loadImport(OntDocumentManager.java:977)
at com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:771)
at com.hp.hpl.jena.ontology.OntDocumentManager.loadImports(OntDocumentManager.java:709)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.loadImports(OntModelImpl.java:1887)
at com.hp.hpl.jena.ontology.impl.OntModelImpl.read(OntModelImpl.java:2050)
at tutorial.Jena.main(Jena.java:30)
Caused by: java.net.SocketException: Permission denied: connect
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
The problem is clearly stated in the first line of the exception trace:
WARN [main] (OntDocumentManager.java:1078) -
An error occurred while attempting to read from
http://www.cs.man.ac.uk/~stevensr/ontology/units.owl.
Msg was 'java.net.SocketException: Permission denied: connect'.
You are trying to read http://www.cs.man.ac.uk/~stevensr/ontology/units.owl, and failing. Since that file does exist (I just checked), the likelihood is either that you are not connected to a network, or that you are behind a web proxy, and so you will have to configure your JVM with the appropriate proxy settings.
Why is your code reading that file? Almost certainly, it's because the ontology you are reading imports the units ontology. Something like:
<> a owl:Ontology ;
owl:imports <http://www.cs.man.ac.uk/~stevensr/ontology/units.owl>
That statement will be recognised by the OntModel loader, which will attempt to fetch and load the imported ontology. If this is not what you want, or it's inconvenient (e.g. because you are not on a network always), then you have three remedies:
turn off imports processing: yourOntModel.getDocumentManager().setProcessImports(false);
remove the owl:imports statement from your source model - opinions vary as to whether or not it's really useful anyway
use Jena's LocationMapper to provide an alternative location for the units.owl file, so that you can still have the owl:imports statement, but the actual file will be read from somewhere else (e.g. on your computer's disk)

Categories

Resources