Exception in Executing Cypher Queries of Neo4j in Java Application - java

I am new to Neo4j Graph Database and I want to create CyperQueries from java Application . I am using the above neo4j manual
http://docs.neo4j.org/chunked/milestone/query-create.html
I am creating nodes from java APplication as follow
public class CreateQuery
{
public static final String DBPATH="D:/Neo4j/CQL";
public static void main(String args[])
{
GraphDatabaseService path=new EmbeddedGraphDatabase(DBPATH);
Transaction tx=path.beginTx();
try
{
Map<String, Object> props = new HashMap<String, Object>();
props .put( "Firstnamename", "Sharon" );
props .put( "lastname", "Eunis" );
Map<String, Object> params = new HashMap<String, Object>();
params.put( "props", props );
ExecutionEngine engine=new ExecutionEngine(path);
ExecutionResult result=engine.execute( "create ({props})", params );
System.out.println(result);
tx.success();
}
finally
{
tx.finish();
path.shutdown();
}
}
}
I am getting the above error. I am not aware of this errors, please can any 1 help in solving as soon as posible .
Exception in thread "main" java.lang.NoClassDefFoundError: com/googlecode/concurrentlinkedhashmap/ConcurrentLinkedHashMap$Builder
at org.neo4j.cypher.internal.LRUCache.<init>(LRUCache.scala:30)
at org.neo4j.cypher.ExecutionEngine$$anon$1.<init>(ExecutionEngine.scala:84)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:84)
at com.neo4j.CreateQuery.main(CretaeQuery.java:33)
Caused by: java.lang.ClassNotFoundException: com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder
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)
... 4 more

You may need to add the latest release of this library (ConcurrentLinkedHashMap for Java):
http://concurrentlinkedhashmap.googlecode.com/files/concurrentlinkedhashmap-lru-1.3.1.jar

The code you shared works fine. I think the problem is with your import statements. They should be like this:
import java.util.HashMap;
import java.util.Map;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.EmbeddedGraphDatabase;

It looks like a library error. Perhaps you have imported the wrong version of something?
Just in case, I should point out that you are meant to use the GDB factory for building an embedded instance:
graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
Not sure that it will make any difference.

Related

BIRT : How to generate and save a report in PDF format using RE API

I am working on a project to generate BIRT reports in PDF format. The application is not meant to be a web application. I tried to follow the Report Engine API example on this link http://wiki.eclipse.org/Simple_Execute_(BIRT)_2.1 but I get an error when I run (Run as -> Java Application) the code. My code is as below.
My code is as follows:
package birt.classicmodels.offices;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class ExecuteReport {
public static void main(String[] args) {
ExecuteReport er = new ExecuteReport();
try {
er.executeReport();
} catch(Exception ex) {
System.out.println(ex.toString());
}
}
public void executeReport() throws EngineException {
IReportEngine engine = null;
EngineConfig config = null;
IReportEngineFactory factory = null;
Object factoryObj = null;
try {
config = new EngineConfig();
config.setBIRTHome("C:\\birt-runtime-4.6.0-20160607\\ReportEngine");
config.setLogConfig("C:\\temp\\test", Level.FINEST);
Platform.startup(config);
factoryObj = Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
factory = (IReportEngineFactory) factoryObj;
engine = factory.createReportEngine(config);
// Open the report design
IReportRunnable design = null;
String designPath = "C:\\birt-runtime-4.6.0-20160607\\ReportEngine\\samples\\hello_world.rptdesign";
design = engine.openReportDesign(designPath);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
PDFRenderOption PDF_OPTIONS = new PDFRenderOption();
PDF_OPTIONS.setOutputFileName("C:\\temp\\test.pdf");
PDF_OPTIONS.setOutputFormat("pdf");
task.setRenderOption(PDF_OPTIONS);
task.run();
task.close();
engine.destroy();
} catch(final Exception ex) {
ex.printStackTrace();
} finally {
Platform.shutdown();
}
}
}
SETUP:
I installed the BIRT designer using the complete BIRT designer download.
I added all the .jars under the libs folder of the BIRT runtime folder to my build path.
The main method was not part of the example I added it with the intention of getting the report saved to my file system.
The design template I'm referencing is the design example that comes with the BIRT engine.
ISSUES:
When I run the code (Run as -> Java Application) I get the following errors:
A pop up dialog with the message:
Java Virtual Machine Launcher
Error: A JNI error has occured, please check your installation and try again
After I click OK on the message dialog, the console is populated with the following error:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/birt/core/framework/PlatformConfig
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException:
org.eclipse.birt.core.framework.PlatformConfig
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 think you are missing following dependency
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.6.0-20160607</version>
</dependency>

Sphinx4 dictionary file not found

I am using Sphinx4 for custome home automatization software and I am stuck on using my custom dict file, for some reason it cant find the file even though I am sure I am using the correct path. This is my code :
package pccomone;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import edu.cmu.sphinx.api.Configuration;
import edu.cmu.sphinx.api.LiveSpeechRecognizer;
import edu.cmu.sphinx.api.SpeechResult;
import edu.cmu.sphinx.api.StreamSpeechRecognizer;
public class Main {
private static final String BODICPATH = "PCCom/src/resource/bodict.dict";
public static void main(String args[]) throws Exception{
Configuration configuration = new Configuration();
configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
configuration.setDictionaryPath(BODICPATH);
//configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict"); use only for large commands!!!!!!!!!
configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
LiveSpeechRecognizer recognizer = new LiveSpeechRecognizer(configuration);
recognizer.startRecognition(true);
SpeechResult result;
while((result = recognizer.getResult()) != null){
String command = result.getHypothesis();
if(command.equalsIgnoreCase("stop")){
recognizer.stopRecognition();
System.exit(0);
}
System.out.println(command);
}
}
}
I didn't come far since I can't get it to use my custom dict file and the included dict file is way to large for the software to work fast and accurate.
This is the Error,
Exception in thread "main" java.lang.RuntimeException: Allocation of
search manager resources failed
at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstSearchManager.allocate(WordPruningBreadthFirstSearchManager.java:247)
at edu.cmu.sphinx.decoder.AbstractDecoder.allocate(AbstractDecoder.java:103)
at edu.cmu.sphinx.recognizer.Recognizer.allocate(Recognizer.java:164)
at edu.cmu.sphinx.api.LiveSpeechRecognizer.startRecognition(LiveSpeechRecognizer.java:47)
at pccomone.Main.main(Main.java:26)
Caused by: java.io.FileNotFoundException: PCCom\src\resource\bodict.dict (The system cannot find the path
specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown
Source)
at java.net.URL.openStream(Unknown Source)
at edu.cmu.sphinx.linguist.dictionary.TextDictionary.allocate(TextDictionary.java:180)
at edu.cmu.sphinx.linguist.lextree.LexTreeLinguist.allocate(LexTreeLinguist.java:332)
at edu.cmu.sphinx.decoder.search.WordPruningBreadthFirstSearchManager.allocate(WordPruningBreadthFirstSearchManager.java:243)
... 4 more

Error when trying to load sound using OpenAL in Java

I was watching this tutorial on making games using java and I was on the part where we import music to our game. However, when I try to load the sounds using a method created in this class:
package main;
import java.util.HashMap;
import java.util.Map;
import org.newdawn.slick.Music;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.Sound;
public class AudioPlayer {
public static Map<String, Sound> soundMap = new HashMap<String, Sound>();
public static Map<String, Music> musicMap = new HashMap<String, Music>();
public static void load(){
try {
soundMap.put("click_sound", new Sound("res/clickSound.ogg"));
musicMap.put("music", new Music("res/background_Music.ogg"));
} catch (SlickException e) {
e.printStackTrace();
}
}
public static Music getMusic(String key){
return musicMap.get(key);
}
public static Sound getSound(String key){
return soundMap.get(key);
}
}
i get an error that says this:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jcraft/jorbis/Info
at org.newdawn.slick.openal.OggInputStream.<init>(OggInputStream.java:35)
at org.newdawn.slick.openal.OggDecoder.getData(OggDecoder.java:311)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:835)
at org.newdawn.slick.openal.SoundStore.getOgg(SoundStore.java:793)
at org.newdawn.slick.Sound.<init>(Sound.java:87)
at main.AudioPlayer.load(AudioPlayer.java:18)
at main.Game.<init>(Game.java:45)
at main.Game.main(Game.java:160)
Caused by: java.lang.ClassNotFoundException: com.jcraft.jorbis.Info
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)
... 8 more
AL lib: (EE) alc_cleanup: 1 device not closed
have I wrote something wrong? i imported the correct external jars and did everything that said in the tutorial. However, I keep getting this error?

exception while using excel workbook

I am getting these exceptions in my code while i m writing some data in excel workbook using poi jars:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/UnsupportedFileFormatException
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 WorkBookDemo.main(WorkBookDemo.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.UnsupportedFileFormatException
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 added following jars:
xmlbeans-2.4.0
poi-ooxml-schemas-3.11
poi-3.11
commons-logging-1.1
dom4j-1.6.1
log4j-1.2.17
import java.io.File;
import java.io.FileOutputStream;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class WorkBookDemo {
public static void main(String[] args)
{
//Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
//Create a blank sheet
XSSFSheet sheet = workbook.createSheet("Employee Data");
//This data needs to be written (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
data.put("2", new Object[] {1, "Amit", "Shukla"});
data.put("3", new Object[] {2, "Lokesh", "Gupta"});
data.put("4", new Object[] {3, "John", "Adwards"});
data.put("5", new Object[] {4, "Brian", "Schultz"});
//Iterate over data and write to sheet
Set<String> keyset = data.keySet();
int rownum = 0;
for (String key : keyset)
{
Row row = sheet.createRow(rownum++);
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr)
{
Cell cell = row.createCell(cellnum++);
if(obj instanceof String)
cell.setCellValue((String)obj);
else if(obj instanceof Integer)
cell.setCellValue((Integer)obj);
}
}
try
{
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File("exps.xlsx"));
workbook.write(out);
out.close();
System.out.println("exps.xlsx written successfully on disk.");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
FileOutputStream out = new FileOutputStream(new File("exps.xlsx"));
A file output stream is an output stream for writing data to a File or to a FileDescriptor. Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileOutputStream (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.
Since you are explicitly creating a File object, and passing the same to FileOutputStream constructor. It assumes that the file "exps.xlsx" is already created. [Reference.]
Incase, it is not, you simply pass the name of the file in FileOutputStream constructor.
FileOutputStream out = new FileOutputStream("exps.xlsx");
This will automatically create the file, incase it is already not created.
Moreover, I tested your given code and used the following Maven dependency and it worked.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10</version>
</dependency>
Incase you are not using a maven project, you can explicitly add the aforementioned jars of the aforementioned versions.
You have missing jar-files. I ran your code in my workspace and I added required jars to build path. It worked successively.
org/apache/poi/UnsupportedFileFormatException is under poi-x.xx-xxx-xx.jar
No error in your code it is correct. Add jars to build path.
the below list of jars required for apachePOI library should all be of same version like shown below :
org.apache.poi.3.11
org.apache.poi-ooxml.3.11
org.apache.poi-ooxml-schemas.3.11
if the above jars of the same library are of different versions, then u will get the exception as "java.lang.NoClassDefFoundError: org/apache/poi/UnsupportedFileFormatException"
you can check for duplicate poi jars as well, suppose you need poi-ooxml-3.9. jar. but in your lib folder there is both poi-ooxml-3.11.jar, poi-ooxml-3.9.jar then remove poi-ooxml-3.11.jar, it should work then.

How to trace back this compiling error?

I am learning to use mahout by starting with a example copied from the book. However, the eclipse compiler gives me the following message:
> Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.<clinit>(FileDataModel.java:119)
at mia.recommender.ch02.RecommenderIntro.main(RecommenderIntro.java:18)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
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)
... 2 more
It seems to me that the the problem comes from FileDataModel.java, which belongs to this libary itself. How to trace back or analyze this error.
The example code is given as follows, which exactly is the one copied from the book. The line causing the trouble is
DataModel model = new FileDataModel(new File("intro.csv"));
import org.apache.mahout.cf.taste.impl.model.file.*;
import org.apache.mahout.cf.taste.impl.neighborhood.*;
import org.apache.mahout.cf.taste.impl.recommender.*;
import org.apache.mahout.cf.taste.impl.similarity.*;
import org.apache.mahout.cf.taste.model.*;
import org.apache.mahout.cf.taste.neighborhood.*;
import org.apache.mahout.cf.taste.recommender.*;
import org.apache.mahout.cf.taste.similarity.*;
import java.io.*;
import java.util.*;
class RecommenderIntro {
public static void main(String[] args) throws Exception {
DataModel model = new FileDataModel(new File("intro.csv"));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(2, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(
model, neighborhood, similarity);
List<RecommendedItem> recommendations =
recommender.recommend(1, 1);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
}
It looks like the SLF4J dependency is not installed/on the classpath: slf4j-api.jar
See: http://www.slf4j.org/

Categories