Intellij Idea 不断给出 JDOMParseException 错误

Intellij Idea constantly gives a JDOMParseException Error

就在几天前,我尝试运行 class,但出现以下错误:

Error:Internal error: (org.jdom.input.JDOMParseException) Error on line 1: Content is not allowed in prolog.
org.jdom.input.JDOMParseException: Error on line 1: Content is not allowed in prolog.
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:946)
    at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:364)
    at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:342)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.tryLoadRootElement(JpsLoaderBase.java:99)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadRootElement(JpsLoaderBase.java:72)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadRootElement(JpsLoaderBase.java:43)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadComponents(JpsLoaderBase.java:55)
    at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadFromDirectory(JpsProjectLoader.java:119)
    at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:98)
    at org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl.loadModel(JpsSerializationManagerImpl.java:41)
    at org.jetbrains.jps.cmdline.JpsModelLoaderImpl.loadModel(JpsModelLoaderImpl.java:45)
    at org.jetbrains.jps.cmdline.BuildRunner.load(BuildRunner.java:78)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:261)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:124)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.run(BuildMain.java:238)
    at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.run(SharedThreadPoolImpl.java:41)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:999)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    ... 21 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:999)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:946)
    at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:364)
    at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:342)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.tryLoadRootElement(JpsLoaderBase.java:99)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadRootElement(JpsLoaderBase.java:72)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadRootElement(JpsLoaderBase.java:43)
    at org.jetbrains.jps.model.serialization.JpsLoaderBase.loadComponents(JpsLoaderBase.java:55)
    at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadFromDirectory(JpsProjectLoader.java:119)
    at org.jetbrains.jps.model.serialization.JpsProjectLoader.loadProject(JpsProjectLoader.java:98)
    at org.jetbrains.jps.model.serialization.impl.JpsSerializationManagerImpl.loadModel(JpsSerializationManagerImpl.java:41)
    at org.jetbrains.jps.cmdline.JpsModelLoaderImpl.loadModel(JpsModelLoaderImpl.java:45)
    at org.jetbrains.jps.cmdline.BuildRunner.load(BuildRunner.java:78)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:261)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:124)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.run(BuildMain.java:238)
    at org.jetbrains.jps.service.impl.SharedThreadPoolImpl.run(SharedThreadPoolImpl.java:41)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

这并没有发生在我之前,我没有更改任何 XML 文件。我尝试运行其他 classes,只是为了得到相同的结果。我尝试了一切,包括重新启动 IntelliJ 甚至卸载和安装它,但错误就是不会停止。

我已经对这个错误做了很多研究,但似乎没有一个适合我的情况。谁能帮我看看这个问题的经过?

注意:这里有一个类似的问题:Intellij IDEA crashed, and now throws an error

但是,我的Intellij IDEA并没有崩溃,只是无法正常运行。

查看所描述的行为,我认为某些内容更改了 .idea/runConfigurations 中的其中一个文件。太糟糕了,您发布的错误消息不包括触发此错误的文件的文件名。用文本编辑器检查 .idea/runConfigurations 中的文件,我希望你在那里找到罪魁祸首。

错误消息表示该文件不是格式正确的 XML 文件。更准确地说,它意味着该文件包含 XML 所说的 "content" 在不允许 "content" 的位置:在 文档之前的文件开头的某处元素。文件的开头在 XML.

中称为 prolog

XML序言可能只包含以下内容:

  • 只有一个 XML 声明,如果它出现必须是第一件事(只有字节顺序标记可以在 XML 声明之前),
  • 评论,如<!-- foo -->
  • 处理类似<?xml-stylesheet ... ?>
  • 的指令
  • 白色space(space、换行、制表符等)
  • 零个或一个 DOCTYPE 声明。

prolog 中的任何其他内容都会破坏 XML 文件,它将不再是 XML,给出您看到的错误。

如果您无法手动修复此问题,即因为文件内容丢失或类似的事情,您还可以执行以下操作:删除所有由 IntelliJ IDEA 创建的文件,并通过从现有项目中导入来创建一个新项目来源。