Hi,
ich versuche eine .odt Textdatei mit Java mittels JODconverter zu convertieren. Klappt eigentlich auch, nur habe ich das Problem, dass genau das erste mal nach einem Neustart des Rechners ich diesen Fehler bekomme:
Danach funktioniert alles wie es soll. Also wie gesagt es passiert nur beim aller ersten Start nachdem der PC hochgefahren ist.
Hier noch der komplette code(bisschen chaotisch wegen rumprobiererei)
ich versuche eine .odt Textdatei mit Java mittels JODconverter zu convertieren. Klappt eigentlich auch, nur habe ich das Problem, dass genau das erste mal nach einem Neustart des Rechners ich diesen Fehler bekomme:
java.lang.NullPointerException
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.disconnect(AbstractOpenOfficeConnection.java:88)
at oostarttest.convert(oostarttest.java:87)
at oostarttest.convert(oostarttest.java:32)
at sendenclass.bestellunggenerierensendenvoid(sendenclass.java:353)
at Zensiert$Lauscher.actionPerformed(Zensiert.java:810)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
at java.awt.Dialog$1.run(Dialog.java:1046)
at java.awt.Dialog$3.run(Dialog.java:1098)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1096)
at java.awt.Component.show(Component.java:1563)
at java.awt.Component.setVisible(Component.java:1515)
at java.awt.Window.setVisible(Window.java:842)
at java.awt.Dialog.setVisible(Dialog.java:986)
at MyMouseListenervoids.genbestellungfenster(MyMouseListenervoids.java:280)
at MyMouseListener.mouseClicked(MyMouseListener.java:226)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6266)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception occurred during event dispatching:
java.lang.RuntimeException: java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
at oostarttest.convert(oostarttest.java:83)
at oostarttest.convert(oostarttest.java:32)
at sendenclass.bestellunggenerierensendenvoid(sendenclass.java:353)
at Zensiert$Lauscher.actionPerformed(Zensiert.java:810)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178)
at java.awt.Dialog$1.run(Dialog.java:1046)
at java.awt.Dialog$3.run(Dialog.java:1098)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Dialog.java:1096)
at java.awt.Component.show(Component.java:1563)
at java.awt.Component.setVisible(Component.java:1515)
at java.awt.Window.setVisible(Window.java:842)
at java.awt.Dialog.setVisible(Dialog.java:986)
at MyMouseListenervoids.genbestellungfenster(MyMouseListenervoids.java:280)
at MyMouseListener.mouseClicked(MyMouseListener.java:226)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
at java.awt.Component.processMouseEvent(Component.java:6266)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79)
at oostarttest.convert(oostarttest.java:76)
... 56 more
Danach funktioniert alles wie es soll. Also wie gesagt es passiert nur beim aller ersten Start nachdem der PC hochgefahren ist.
Hier noch der komplette code(bisschen chaotisch wegen rumprobiererei)
Java:
import java.io.*;
import java.net.*;
import com.artofsolving.jodconverter.openoffice.connection.*;
import com.artofsolving.jodconverter.*;
import com.artofsolving.jodconverter.openoffice.converter.*;
public class oostarttest{
static Process p = null;
static int tester = 0;
public static void main(String[] args) throws Exception {
//PackerforMB.unzip();
//Find.change();
//PackerforMB.zip();
// String inputFile = "packed.odt";
// String outputFile = "packed.pdf";
//
// ensureStartedOpenOfficeService();
// convert(inputFile,outputFile);
// p.destroy();
convert();
}
public static void convert(){
String inputFile = "Bestellungmod.odt";
String outputFile = "Bestellung.pdf";
//ensureStartedOpenOfficeService();
// if(tester==0){
// p.destroy();
// }
ensureStartedOpenOfficeService();
convert(inputFile,outputFile);
if(tester==0){
p.destroy();
}
try{
p.waitFor();
}
catch ( Exception e ){}
//
// Runtime.getRuntime().exec("cmd /c taskkill /IM soffice.exe");//end process
// }
// catch ( Exception e ){}
System.out.println("done!!!");
}
private static void ensureStartedOpenOfficeService(){
try{
new Socket( "localhost", 8100 );
tester = 1;
}
catch ( Exception e ){
tester = 0;
String path = "C:/Users/Dennis/Desktop/Programmieren/oo/OpenOfficePortable/App/openoffice/program/";
ProcessBuilder processBuilder = new ProcessBuilder(path+"soffice.exe", "-headless", "-accept=\"socket,host=localhost,port=8100;urp;\"", "-nofirststartwizard" );
try{
p = processBuilder.start();
System.out.println("ttt\"");
}
catch( IOException ioe ){
throw new RuntimeException( ioe );
}
}
}
public static void convert( String source, String destination ){
ensureStartedOpenOfficeService();
OpenOfficeConnection connection = null;
try{
connection = new SocketOpenOfficeConnection( 8100 );
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter( connection );
File inputFile = new File( source );
File outputFile = new File( destination );
converter.convert( inputFile, outputFile );
}
catch ( ConnectException e ){
throw new RuntimeException( e );
}
finally {
try {
connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
//bError = true;
}
}
}
}