How to trace back this compiling error? - java

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/

Related

i get ClassNotFoundException when i try to read from excel file

When i try to read from excel file using apace poi i get the ClassNotFoundException followed by other errors and i have imported all the necessary jar files in the reference library
by the way i'm still new to coding
heres the code :
import java.io.*;
import java.io.File;
import java.io.FilterInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.*;
import org.apache.poi.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Test {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileInputStream F = new FileInputStream("Carbcounting.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(F);
XSSFSheet sheet = wb.getSheetAt(0);
FormulaEvaluator formulaEva = wb.getCreationHelper().createFormulaEvaluator();
for(Row row : sheet){
for(Cell cell : row){
System.out.print(cell.getStringCellValue());
}
}
System.out.println();
}
}
and heres all the errors i'm getting when i try to run it :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at project.Test.main(Test.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
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)
... 1 more
You need to Add commons-collections4-x.x.jar file in your build path and try it again. It should work.
Get it from here: https://mvnrepository.com/artifact/org.apache.commons/commons-collections4/4.0
Also, just adding up:
You are getting this error(NoClassDefFoundError) majorly for two reasons:
Java Virtual Machine is not able to find a particular class at runtime which was available at compile time.
If a class was present during compile time but not available in java classpath during runtime.

Hadoop class not found exception

I'm working on simple program on hadoop, I followed this tutorial steps:
http://www.bogotobogo.com/Hadoop/BigData_hadoop_Creating_Java_Wordcount_Project_with_Eclipse_MapReduce2.php
even though I tried it on two different machines, it keeps showing this exception:
Exception in thread "main" java.lang.ClassNotFoundException: test.java
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:270)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
package pa2;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class test extends Configured implements Tool{
public int run(String[] args) throws Exception
{ if (args.length<2)
{
System.out.println("plz give proper arguments");
return -1;
}
//creating a JobConf object and assigning a job name for identification purposes
JobConf conf = new JobConf(test.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
conf.setMapperClass(mapper.class);
conf.setMapOutputKeyClass(Text.class);
conf.setMapOutputValueClass(IntWritable.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
return 0;
}
public static void main(String[] args) throws Exception
{
// this main function will call run method defined above.
int exitcode = ToolRunner.run(new test(),args);
System.exit(exitcode);
}
}
can you please tell me what is wrong here?
update:
mapper class:
package pa2;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class mapper extends MapReduceBase
implements Mapper<LongWritable,Text, Text, IntWritable>
{
public void map(LongWritable Key, Text value,
OutputCollector<Text, IntWritable> output, Reporter r)
throws IOException {
int i=0;
String [] array = new String [50];
String name;
String year;
String s=value.toString();
for (String word:s.split(",")){
word = s.substring(0, s.indexOf(",")+1);
year= word.substring(0, s.indexOf(",")+1);
name=word.substring(s.indexOf(",")+1);
int theyear= Integer.parseInt(year);
if(theyear<2000){
array[i] =name;
output.collect(new Text(word), new IntWritable(1));
i++;}
}
}
}
I haven't written the reducer class. I exported the project as jar file,and I made a text file called movies to be the input of the program. then wrote this in the terminal:
[cloudera#quickstart ~]$ cd workspace
[cloudera#quickstart workspace]$ ls
pa2 pa2.jar training
[cloudera#quickstart workspace]$ hadoop jar pa2.jar test movies.txt output.txt
Exception in thread "main" java.lang.ClassNotFoundException: test
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:270)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
No guarantees this is the solution to the immediate problem, but
package pa2;
This is appended to the class name. In other words, the fully-qualified class name is pa2.test.
So, try
hadoop jar ~/workspace/pa2.jar pa2.test input output
If you used the default package like that tutorial showed, you wouldn't need to specify the package on the command line.
The actual name of your map class should be provided here
conf.setMapperClass(mapper.class);
If you are trying to use the default map class, then write "Mapper.class".

BIRT csv emitter plugin error -

I am trying to get a CSV from the report using this well-known plugin and the example from its documentation, but it throws an exception. I wonder why, because I just copied most of the code from the doc.
My code is:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.emitter.csv.CSVRenderOption;
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;
public class RunReport {
static void runReport() throws FileNotFoundException, BirtException {
String resourcePath = "C:\\Users\\hpsa\\workspace\\My Reports\\";
FileInputStream fs = new FileInputStream(resourcePath + "new_report_1.rptdesign");
IReportEngine engine = null;
EngineConfig config = new EngineConfig();
config.setEngineHome("C:\\birtre\\birt-runtime-4_3_2\\");
config.setLogConfig("C:\\birtre\\", Level.FINE);
config.setResourcePath(resourcePath);
Platform.startup(config);
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
engine.changeLogLevel(Level.FINE);
IReportRunnable design = engine.openReportDesign(fs);
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
CSVRenderOption csvOption = new CSVRenderOption();
String format = CSVRenderOption.OUTPUT_FORMAT_CSV;
csvOption.setOutputFormat(format);
csvOption.setOutputFileName("newBIRTcsv.csv");
csvOption.setShowDatatypeInSecondRow(true);
csvOption.setExportTableByName("SecondTable");
csvOption.setDelimiter("\t");
csvOption.setReplaceDelimiterInsideTextWith("-");
task.setRenderOption(csvOption);
task.setEmitterID("org.eclipse.birt.report.engine.emitter.csv");
task.run();
task.close();
Platform.shutdown();
System.out.println("Report Generated Sucessfully!!");
}
public static void main(String[] args) {
try {
runReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I am getting the exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/runtime/CoreException
at org.eclipse.birt.core.framework.Platform.createPlatformLauncher(Platform.java:115)
at org.eclipse.birt.core.framework.Platform.startup(Platform.java:74)
at com.demshin.birttest.RunReport.runReport(RunReport.java:26)
at com.demshin.birttest.RunReport.main(RunReport.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.runtime.CoreException
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)
... 4 more
I found the package org.eclipse.core.runtime and registered in the build path, but then I am getting the same exception. Indeed, there are no any CoreException.class in the org.eclipse.core.runtime package. What am I doing wrong?
Setting the engine home is deprecated and most of the time it will prevent the Platform to start, such in your case. Remove this line:
config.setEngineHome("C:\\birtre\\birt-runtime-4_3_2\\");
You just have to ensure the birt runtime 4.3.2 is in the classpath of your context. Furthermore i would recommend you try to generate a native format such pdf first, and then try with a csv format.
I was trying a lot of variants of importing different jars, but finally i found the weird decision here:
go to the Project Explorer, right-mouse click on properties for the
project, go to Java Build path, Click on the External Jars button,
then select all the libraries under
C:\birt_runtime\birt-runtime-2_1_0\ReportEngine\lib\ folder
This made chaos there, but at least it starts.

Exception in Executing Cypher Queries of Neo4j in Java Application

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.

Downloading & saving graphic

I am having difficulties saving pictures that I have loaded. The picture is saved under the same folder where this program is. An error keeps reappearing. The error screen is below
Error
---------- Capture Output ----------
>"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" loadapicture
java.lang.NoClassDefFoundError: loadapicture
Caused by: java.lang.ClassNotFoundException: loadapicture
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)
Could not find the main class: loadapicture. Program will exit.
Exception in thread "main"
> Terminated with exit code 1.
My program
import hsa.*;
import java.awt.*;
// Look at all of these extra imports needed for a picture file
import java.io.File;
import java.io.IOException;
import java.awt.image.*;
import javax.imageio.*;
public class loadapicture{
public static void main(String[] args){
Console con = new Console();
// Variables need to open a picture file
File tictactoefile;
BufferedImage tictactoeimage;
tictactoefile = null;
tictactoeimage = null;
// Now that the variables are created.. Time to load the picture into the variables
// BTW You need to load the file using a block called try/catch
// Becuase if the file does not exist, you need to catch the error
// You can use jpg, gif, and bmp
try{
// Trying to open the file and loading it
tictactoefile = new File("");
tictactoeimage = ImageIO.read( owin.jpeg);
}catch(IOException e){
// If the file is not found, this will happen
con.println("ERROR... IMAGE FILE NOT FOUND");
}
con.drawImage(tictactoeimage, 100, 100, null);
// Yes you can do all of this in a method
}
}
How to download & save image correctly?
I guess you just need to specify path to your class
"C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" -classpath <path to your class> loadapicture

Categories