0

我已经完成了@Perception 所说的关于架构 URI 的内容,但现在我有另一个例外。有谁知道是什么问题?非常感谢。

我有来自方法 Git60Manager.doImportMod1GtFile 的这段代码,它使用 xsd 模板解组文件:

String schema = "///META-INF/templates/git60_data_mod1_def.xsd";
isr = new InputStreamReader(GIT60FileMod1.class.getResourceAsStream(schema));
Unmarshaller unmarshaller = new Unmarshaller(isr, main);

这是 xsd 文件:

<xs:annotation>
<xs:documentation xml:lang="en">
  GIT60 schema Mod 1 (Data)
</xs:documentation>
</xs:annotation>

<xs:include id="git60_mod1_def.xsd" schemaLocation="./git60_mod1_def.xsd" />

<xs:element name="mainData" type="GIT60FileMod1Data" jrb:length="100" />

<xs:complexType name="GIT60FileMod1Data">
    <xs:sequence>
        <xs:element name="git60Tax" type="GIT60FileTaxMod1" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

这是我运行应用程序时的异常,在我得到 java.net.MalformedURLException 之前:

 java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at com.samelan.gitim.core.service.io.account.impl.GIT60Manager.doImportMod1GtFile(GIT60Manager.java:1256)
at com.samelan.gitim.core.service.managers.GtFileProcessorManagerTest.testProcFilesNewTemplateGit60(GtFileProcessorManagerTest.java:717)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
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)
4

1 回答 1

0

GIT60FileMod1.class.getResourceAsStream(schema)正在返回 null。发生这种情况是因为它找不到该资源。值得浏览一下此方法的文档

如果类单独运行或打包到 JAR 文件中,则会发生不同的事情。具体来说,它开始的根以及事物的打包方式将会改变。

于 2013-01-29T01:44:34.543 回答