Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SaxLoader中的Sphinx4 nullpointerexception_Java_Eclipse_Maven_Jar_Cmusphinx - Fatal编程技术网

Java SaxLoader中的Sphinx4 nullpointerexception

Java SaxLoader中的Sphinx4 nullpointerexception,java,eclipse,maven,jar,cmusphinx,Java,Eclipse,Maven,Jar,Cmusphinx,我在应用程序中使用spinx4-5prealpha。当我在eclipse中运行应用程序时,一切正常。我使用Maven加载依赖项。当我将项目导出为可运行的jar文件并运行该文件时,我得到以下结果: Exception in thread "recognizerEngine" java.lang.NullPointerException at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:71) at edu.cmu.

我在应用程序中使用spinx4-5prealpha。当我在eclipse中运行应用程序时,一切正常。我使用Maven加载依赖项。当我将项目导出为可运行的jar文件并运行该文件时,我得到以下结果:

Exception in thread "recognizerEngine" java.lang.NullPointerException
    at edu.cmu.sphinx.util.props.SaxLoader.load(SaxLoader.java:71)
    at edu.cmu.sphinx.util.props.ConfigurationManager.<init>(ConfigurationManager.java:58)
    at edu.cmu.sphinx.api.Context.<init>(Context.java:59)
    at edu.cmu.sphinx.api.Context.<init>(Context.java:44)
    at edu.cmu.sphinx.api.AbstractSpeechRecognizer.<init>(AbstractSpeechRecognizer.java:42)
    at system.core.RecognizerEngineComponents.LiveSpeechRecognizerExtention.<init>(LiveSpeechRecognizerExtention.java:36)
    at system.core.RecognizerEngine.run(RecognizerEngine.java:64)
    at java.lang.Thread.run(Unknown Source)
项目:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>Speech Recognizer</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.m2e.core.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.m2e.core.maven2Nature</nature>
        <nature>fr.obeo.dsl.viewpoint.nature.modelingproject</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

语音识别器
org.eclipse.jdt.core.javabuilder
org.eclipse.m2e.core.maven2Builder
org.eclipse.m2e.core.maven2Nature
fr.obeo.dsl.viewpoint.nature.modelingproject
org.eclipse.jdt.core.javanature
pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SpeechRecognizer</groupId>
  <artifactId>SpeechRecognizer</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.3</source>
          <target>1.2</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-data</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-samples</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

4.0.0
语音识别器
语音识别器
0.0.1-快照
src
maven编译器插件
3.1
1.3
1.2
edu.cmu.sphinx
狮身人面像核心
1.0-快照
edu.cmu.sphinx
狮身人面像数据
1.0-快照
edu.cmu.sphinx
狮身人面像4父代
1.0-快照
聚甲醛
edu.cmu.sphinx
狮身人面像样本
1.0-快照

如何加载配置文件

你必须使用 在执行jar文件时加载任何配置


使用maven时,将检查
src/main/resources
文件夹,以包括
classpath
上的资源。要正确创建单个可执行jar,您需要确保Eclipse将依赖项解压到正确的位置。打包后,xml文件必须位于jar内的
/edu/cmu/sphinx/api
文件夹中。使用
en-us
的所有路径都不合理,因为它不是需要配置文件的地方

要获得有关此问题的进一步帮助,您需要提供有关项目布局和IDE使用方式的更多信息。您似乎混淆了maven和eclipse构建,您可以使用maven

  • 转到计算机上的sphinx4-5prealpha-src目录

  • 要编辑Sphinx API,请转到sphinx4-5prealpha-src\sphinx4 core\src\main\java\edu\cmu\Sphinx\API目录,并根据需要编辑这些文件

  • 在您的计算机上下载Gradle并使用Git Bash或Terminal。确保您还有一个可以在shell上运行的Java编译器

  • 使用shell键入命令,确保您位于sphinx4-5prealpha目录中:

  • cd sphinx4-5Perapha

    建立梯度

  • 该命令将为这些文件夹中包含的源代码创建.jar文件,如果您将所有这些.jar文件插入到项目中,它将与您对代码所做的编辑一起运行
  • 获取以下文件中包含的所有jar文件:

    sphinx4-5Realpha/sphinx4核心/构建/库


    sphinx4-5prealpha/sphinx4 data/build/libs

    问题在于spinxapi加载文件时。它使用
    getResource()
    。确定。请用您的代码编辑这个问题:“当使用eclipse时,maven将自动加载src/main/resources文件夹中的任何配置文件。”帮助我理解了一些事情:DMaven不会“加载”任何东西。它只是一个构建系统,它创建一个jar包,并将src/main/resources中的所有文件添加到jar中。应用程序加载资源。我不明白项目布局是什么意思,也不明白我如何使用IDE?我不明白为什么eclipse在导出为jar时将资源文件添加到名为
    resources
    的文件夹中。可能是因为根目录中有另一个名为
    edu
    的目录,其中包含sphinx类文件?您需要回答以下问题:如何包含sphinx4依赖项。是否将JAR添加到类路径?是否将外部JAR添加到类路径?是否导入sphinx4源并添加从属项目?您使用maven还是gradle来构建项目?您应该将JAR添加到类路径,而不是将sphinx4项目源作为依赖项目导入。导出jar时,您是“提取所需库”还是“打包所需库”。使用gradle构建系统而不是Eclipse也更好,它是更可靠的构建系统。如果您仍然想坚持使用Eclipse,您需要选择“提取所需库”,而不是“打包所需库”。如果您使用maven,那么您可以使用maven来构建jar,而不是像这里所描述的那样导出:对我来说,您似乎仍然添加项目作为引用。您可以从工作区中删除sphinx4项目,如果您将文件正确添加到maven中,它仍然可以生成。您还可以共享项目中的.classpath和.project以及pom.xml文件,以明确情况。
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>SpeechRecognizer</groupId>
      <artifactId>SpeechRecognizer</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
              <source>1.3</source>
              <target>1.2</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-data</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-parent</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-samples</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
    </project>