This Question is Possibly Answered

1 "correct" answer available (4 pts) 2 "helpful" answers available (2 pts)
1 Replies Last post: Jun 15, 2007 3:04 PM by Serge Piletsky  
Nick Armstrong   1 posts since
Jun 15, 2007
Currently Being Moderated

Jun 15, 2007 12:00 PM

OleObject is not created

I have a WebStart application that embeds a Word container to allow the user to use mail merge and then save the document back to a database.

 

The problem I have is when I try to load an existing document using the container.load(byte[]) method.

The actual call appears to work fine and is called within an olemessageloop as follows:

 

container = new OleContainer();
// check to see if a document has already been created
byte[] existingDocument = getDocument();
if(existingDocument != null && existingDocument.length > 0)
{
    mContainer.load(existingDocument);
}

 

However, when I try to show the container as below:

 

app.container.doVerb(OleVerbs.SHOW);

 

it throws the following exception:

 


Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: OleObject is not created.

 

Creating a new document and opening a file is no problem. The only problem is when I try to use the load method using a byte array.

 

Any ideas??

 

Thanks

Nick

Serge Piletsky TeamDev Ltd. 670 posts since
Apr 24, 2006
Currently Being Moderated
1. Jun 15, 2007 3:04 PM in response to: Nick Armstrong
Re: OleObject is not created

Hi Nick,

 

I cannot reproduce such problem. Here the comlete test applciation that I used for testing:

 


import com.jniwrapper.util.StreamUtils;
import com.jniwrapper.win32.automation.OleContainer;
import com.jniwrapper.win32.ole.types.OleVerbs;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileInputStream;

public class Test {
    public static void main(String[] args) throws Exception {

        JFrame frame = new JFrame("TestFrame");
        frame.setSize(800, 600);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container contentPane = frame.getContentPane();
        contentPane.setLayout(new BorderLayout());

        final OleContainer container = new OleContainer();
        contentPane.add(container);

        frame.setVisible(true);

        byte[] existingDocument = StreamUtils.readBytes(new FileInputStream("c:\\Test.dat"));
        if (existingDocument != null && existingDocument.length > 0) {
            container.load(existingDocument);
        }
        container.doVerb(OleVerbs.SHOW);

        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent windowEvent) {
                container.destroyObject();
            }
        });

    }
}

 

The "c:
Test.dat" is the file that contains serialized document. In order to create such file you can simply use the following example:

 


        container.open(new File("c:\\Test.doc"));
        container.save(new FileOutputStream(new File("c:\\Test.dat")));

 

Does this sample work in your case?

 

Also, what version of ComfyJ do you use?

 

-Serge

More Like This

  • Retrieving data ...