XML Einleseproblem

NiklasP

Neues Mitglied
Moin alle zusammen,

Fehlerquelle ist dieser Code:
Java:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("C:\\plainfile.xml"));

Ergebnis:
document ist "null".

Ich weiß wirklich nicht was die Ursache ist. Könnte mir bitte jemand weiterhelfen?
 

NiklasP

Neues Mitglied
Stacktrace:
Java:
Apr 05, 2014 9:34:14 AM de.company.util.TestXMLEncryption testEncrypter
Information: Parse Sample Doc
Apr 05, 2014 9:34:14 AM de.company.util.TestXMLEncryption testEncrypter
Information: Encryption Key generated
Apr 05, 2014 9:34:14 AM de.company.util.TestXMLEncryption testEncrypter
Information: Key encryption key stored in E:\KeyEncryptionKey.txt
Apr 05, 2014 9:34:15 AM de.company.util.TestXMLEncryption testEncrypter
Information: Create KeyInfo and Encrypt Document
Apr 05, 2014 9:34:15 AM de.company.util.TestXMLEncryption testEncrypter
Information: Fehler bei Verschlüsselung
Apr 05, 2014 9:34:15 AM de.company.util.TestXMLEncryption testEncrypter
Information: null
java.lang.NullPointerException
	at org.apache.xml.security.encryption.XMLCipher.encryptKey(Unknown Source)
	at de.company.util.XMLEncrypter.createKeyInfoAndXMLCipher(XMLEncrypter.java:81)
	at de.company.util.TestXMLEncryption.testEncrypter(TestXMLEncryption.java:38)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:255)
	at junit.framework.TestSuite.run(TestSuite.java:250)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
 

amutz

Mitglied
Hallo,

versuch mal das, vielleicht passen Deine Importe nicht
Java:
import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

und dann

Java:
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setNamespaceAware(true);
		DocumentBuilder builder = null;
		try {
			builder = factory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			Document document = builder.parse(new File("C:\\plainfile.xml"));
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 

Neue Themen


Oben