Wer kennt sich ein bischen mit java COM Programmierung aus?

neomon

Mitglied
Hallo zusammen,

ich bekomme folgenden Fehler bei der Ausführung meines Programms :

Exception in thread "AWT-EventQueue-1" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: ActiveExplorer
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.get(Dispatch.java)
at Dropzone.DTListenerJ.drop(DTListenerJ.java:37)
at java.awt.dnd.DropTarget.drop(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer.access$800(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(Unknown Source)
at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(Unknown Source)
at sun.awt.dnd.SunDropTargetEvent.dispatch(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processDropTargetEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Mein Sourcecode lautet:

package Dropzone;
Java:
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class DTListenerJ implements DropTargetListener {
	
	public void dragEnter(DropTargetDragEvent dtde) {
	    System.out.println("Drag Enter");
	}
	 
	public void dragExit(DropTargetEvent dte) {
		System.out.println("Drag Exit");
	}
	 
	public void dragOver(DropTargetDragEvent dtde) {
	    System.out.println("Drag Over");
	}
	 
	public void dropActionChanged(DropTargetDragEvent dtde) {
	    System.out.println("Drop Action Changed");
	}
	 
	public void drop(DropTargetDropEvent dtde) {
		ActiveXComponent xl = new ActiveXComponent("Outlook.Application");

		Object explorer = Dispatch.get(xl,"ActiveExplorer").toDispatch();
		Object selection = Dispatch.get(explorer, "Selection").toDispatch();
		Variant count = Dispatch.get(selection, "Count");

		for (int mailIndex = 1; mailIndex <= count.toInt(); mailIndex++ ) {

			Object mailItem = Dispatch.call(selection, "Item", new Variant(mailIndex)).toDispatch();

			Variant senderName = Dispatch.get(mailItem, "SenderName");
			Variant subject = Dispatch.get(mailItem, "Subject");
			Variant body = Dispatch.get(mailItem, "Body");

			String emailFileName = subject.toString() +".txt";

			String fullPath = "C:\\bla" + File.pathSeparator + emailFileName;
			try {
				File email = new File(fullPath);
				PrintWriter writer = new PrintWriter( new FileWriter(email) );
				writer.println("From: "+ senderName );
				writer.println("Subject: "+ subject);
				writer.println("");
				writer.print( body );
				writer.close();
			}
			catch (IOException e) {
				System.out.println("IOException writing e-mail with subject: '"+ subject +"'");
				continue;
			}

			Object attachments = Dispatch.get(mailItem, "Attachments").toDispatch();
				Variant attachmentCount = Dispatch.get(attachments, "Count");

				if ( attachmentCount.toInt() > 0 ) {

					for( int attachmentIndex = 1; attachmentIndex<=attachmentCount.toInt(); attachmentIndex++ ) {

						Object attachment = Dispatch.call(attachments, "Item", new Variant(attachmentIndex)).toDispatch();
						Variant fileNameVariant = Dispatch.get(attachment, "FileName");
						String fileName = fileNameVariant.toString();

						Variant saveResult = Dispatch.call(attachment, "SaveAsFile", "C:\\bla"+File.pathSeparator+fileName);
					}
				}
			}

		}
	}

Woher kommt dieser Fehler dass ich ich die Jacob COM-Exception bekomme?

Bin für jede Hilfe dankbar :)

Mfg Andreas
 
Als tipp:
Benutz beim einfuegen von source code [.code] code [./code]
aber ohne Punkte :D Das findest du auch oben in der Leiste fuer Formatierungen, wenn du einen Beitrag erstellst, untere Zeile dritte Symbol von rechts. Dann ist es besser zu lesen und du wirst sicher schneller Hilfe bekommen.
 
Erstmal vorweg: Benutz doch bitte den Code-Tag, das macht das ganze um einiges übersichtlicher.

Alle Imports ok? Kenn mich nun nicht mit COM aus, aber hast du auch mal die Suche hier benutzt?;)

Vielleicht hilft dir ja das

LG Tobi
 

Neue Beiträge

Zurück