Source fie ->
location c:/program files/java/jdk1.6.0_07/bin
import java.io.File;
import java.io.IOException;
import jxl.*;
public class Geeta {
private String inputFile;
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws Exception {
File inputWorkbook = new File(inputFile);
Workbook w;
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
Cell a1 = sheet.getCell(0,0);
String stringa1 = a1.getContents();
System.out.println(stringa1);
}
public static void main(String[] args) throws Exception {
Geeta test = new Geeta();
test.setInputFile("c:/Progra~1/Java/jdk1.6.0_07/bin/jxlrwtest.xls");
test.read();
}
}
compiled as
javac -classpath jxl.jar Geeta.java
When I try to execute it says.. NoClassDefFoundError
java -jar jxl.jar Geeta
C:\Program Files\Java\jdk1.6.0_07\bin>java -jar jxl.jar Geeta
Exception in thread "main" java.lang.NoClassDefFoundError: Geeta
Caused by: java.lang.ClassNotFoundException: Geeta
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Plz. advice...
I had an error with jxl execution, it was about the CLASSPATH
This works to me:
Change or set the CLASSPATH in Environment Variables:
Open Explorer (Windows-E)
Right-click on Computer
Select Properties
On the "Advanced" Tab select "Environment Variables..."
On System variables window, Edit or Add a new variable named: CLASSPATH
On Variable Value set the place where jxl.jar is, example: .;C:\YourPath\jxl.jar
Open a new CMD window and compile as usual.
Your run command should look like this:
java -classpath jxl.jar;. Geeta
Related
I'm trying to pass a file from the main method to another class that should handle it, but while the file is recognized in the main class, it throws this error in the second one.
Exception in thread "main" java.io.FileNotFoundException: file:/home/giovanni/Desktop/spring-course/exercises-part2/word-inspection/target/classes/words.txt (File o directory non esistente)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.util.Scanner.<init>(Scanner.java:639)
at com.vanny96.WordInspection.<init>(WordInspection.java:16)
at com.vanny96.App.main(App.java:13)
The path for the file is correct, and the file is there, so I have no idea why it isn't working.
I tried looking around for a solution but couldn't find any, and the fact that the file works fine in the main method while not in another one confused me a lot, if you could point me to a thread where this is solved it would be enough!
Here is the code:
Main App
package com.vanny96;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
public class App {
public static void main(String[] args) throws FileNotFoundException
{
URL fileUrl = App.class.getClassLoader().getResource("words.txt");
File file = new File(fileUrl.toString());
WordInspection inspector = new WordInspection(file);
}
}
WordInspection class
package com.vanny96;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class WordInspection {
private File file;
private Scanner reader;
public WordInspection(File file) throws FileNotFoundException {
this.file = file;
this.reader = new Scanner(this.file);
}
}
I think the Scanner is not able to resolve the file as an URL, but is able to resolve it as an URI.
If you change the line:
File file = new File(fileUrl.toString());
to
File file = new File(fileUrl.toURI());
your Scanner should be able to resolve the file (i have tested it). You will have to add an additional throws class for the toUri() method.
Hi everyone I am currently trying to write a program for an assignment that takes 4 separate text files then using a method, combines them into one. I was wondering if someone could help me find out what is wrong with this code. When i try to run it I get a error reading the following:
"Exception in thread "main" java.io.FileNotFoundException: wonder1.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at asig5.combineFile(asig5.java:26)
at asig5.main(asig5.java:17) "
Code:
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
public class asig5 {
public static void main(String[] args) throws FileNotFoundException {
PrintWriter newtext = new PrintWriter("wonder5.txt");
File f0 = new File("wonder1.txt");
File f1 = new File("wonder2.txt");
File f2 = new File("wonder3.txt");
File f3 = new File("wonder4.txt");
combineFile(f0, newtext);
combineFile(f1, newtext);
combineFile(f2, newtext);
combineFile(f3, newtext);
newtext.close();
}
public static void combineFile(File f0, PrintWriter output) throws FileNotFoundException {
Scanner input = new Scanner(f0);
while (input.hasNext()) {
String part1 = input.nextLine();
System.out.println(part1);
output.print(part1);
}
}
}
When you write new File("wonder1.txt") it means that if your project location is ~/Folder/MyProject, your file's full path is ~/Folder/MyProject/wonder1.txt.
You need to provide full path to your file or put your files at the root of your project folder.
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.
I am an absolute newbee in asterisk. I am trying to use asterisk-java for event listening through AMI. I am currently using the version 11.2.1 asterisk. When I tries to compiles the code as
javac -cp asterisk-java-0.3.jar HelloEvents.java
it complets successfully. But when I try to execute the file, I give the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: HelloEvents
Caused by: java.lang.ClassNotFoundException: HelloEvents
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: HelloEvents. Program will exit.
the code is
import java.io.IOException;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.ManagerEventListener;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.StatusAction;
import org.asteriskjava.manager.event.ManagerEvent;
public class HelloEvents implements ManagerEventListener
{
private ManagerConnection managerConnection;
public HelloEvents() throws IOException
{
ManagerConnectionFactory factory = new ManagerConnectionFactory(
"localhost", "manager", "password");
this.managerConnection = factory.createManagerConnection();
}
public void run() throws IOException, AuthenticationFailedException,
TimeoutException, InterruptedException
{
// register for events
managerConnection.addEventListener(this);
// connect to Asterisk and log in
managerConnection.login();
// request channel state
managerConnection.sendAction(new StatusAction());
// wait 10 seconds for events to come in
Thread.sleep(10000);
// and finally log off and disconnectaaaa
managerConnection.logoff();
}
public void onManagerEvent(ManagerEvent event)
{
// just print received events
System.out.println(event);
}
public static void main(String[] args) throws Exception
{
HelloEvents helloEvents;
helloEvents = new HelloEvents();
helloEvents.run();
}
}
java -cp ".;asterisk-java.jar" HelloEvents
works fine.
And the class path separator is OS dependent. If you are using linux / mac, use : (colon) instead of ; (semicolon)
We can avoid adding class path every time while compiling or executing code. Now go to the location where jar file is located. Then run,
For linux :- export CLASSPATH=$CLASSPATH:asterisk-java-2.0.3.jar:.
For windows:- set CLASSPATH=$CLASSPATH:asterisk-java-2.0.3.jar:.
Now compile code by
javac HelloEvents.java
Execute it by java HelloEvents
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