关于Eclipse导入maven项目报空指针异常

今天新建了一个maven项目,因为是通过公司的工具新建的,代码拉下来就有src、pom.xml文件。

导入Eclipse却报空指针异常。具体如下:

关于Eclipse导入maven项目报空指针异常

An error has occurred. See error log for more details.
java.lang.NullPointerException

一时没看明白是为什么,搜了一下Eclipse的日志文件。

日志在workSpace的.metadata里的.log文件。

点开查看,如下:

!SESSION 2019-09-16 14:31:23.461 -----------------------------------------------

eclipse.buildId=4.7.3.M20180330-0640

java.version=1.8.0_144

java.vendor=Oracle Corporation

BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=zh_CN

Framework arguments:  -product org.eclipse.epp.package.jee.product

Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product

 

!ENTRY org.eclipse.egit.ui 2 0 2019-09-16 14:31:42.700

!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git

user global configuration and to define the default location to store repositories: 'C:\Users\flyin'. If this is

not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and

EGit might behave differently since they see different configuration options.

This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.

 

!ENTRY org.eclipse.epp.logging.aeri.ide 2 17 2019-09-16 14:31:53.542

!MESSAGE Server ‘org.eclipse.epp.logging.aeri.ide.server’ failed with exception: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $. ; version: 2.0.7.v20170906-1327

!STACK 0

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)

at com.google.gson.Gson.fromJson(Gson.java:887)

at com.google.gson.Gson.fromJson(Gson.java:852)

at com.google.gson.Gson.fromJson(Gson.java:801)

at org.eclipse.epp.internal.logging.aeri.ide.server.json.Json.deserialize(Json.java:91)

at org.eclipse.epp.internal.logging.aeri.ide.server.mars.IO.refreshConfiguration(IO.java:66)

at org.eclipse.epp.internal.logging.aeri.ide.server.mars.ServerConnection.startUp(ServerConnection.java:124)

at com.google.common.util.concurrent.AbstractIdleService$DelegateService$1.run(AbstractIdleService.java:62)

at com.google.common.util.concurrent.Callables$4.run(Callables.java:122)

at java.lang.Thread.run(Thread.java:748)

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)

at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:213)

... 9 more

 

!ENTRY org.eclipse.jface 4 2 2019-09-16 14:33:23.521

!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface".

!STACK 0

java.lang.NullPointerException

at org.eclipse.m2e.core.project.ProjectImportConfiguration.cleanProjectNameComponent(ProjectImportConfiguration.java:109)

at org.eclipse.m2e.core.project.ProjectImportConfiguration.getProjectName(ProjectImportConfiguration.java:83)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.isAlreadyExists(MavenImportWizardPage.java:615)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage$ProjectLabelProvider.getForeground(MavenImportWizardPage.java:812)

at org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.getForeground(DelegatingStyledCellLabelProvider.java:140)

at org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.update(DelegatingStyledCellLabelProvider.java:123)

at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:141)

at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:946)

at org.eclipse.jface.viewers.CheckboxTreeViewer.doUpdateItem(CheckboxTreeViewer.java:120)

at org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:117)

at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)

at org.eclipse.ui.internal.JFaceUtil.lambda$0(JFaceUtil.java:44)

at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)

at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:1025)

at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:475)

at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)

at org.eclipse.ui.internal.JFaceUtil.lambda$0(JFaceUtil.java:44)

at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)

at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2159)

at org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:840)

at org.eclipse.jface.viewers.AbstractTreeViewer.lambda$0(AbstractTreeViewer.java:817)

at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)

at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:792)

at org.eclipse.jface.viewers.TreeViewer.createChildren(TreeViewer.java:595)

at org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:763)

at org.eclipse.jface.viewers.AbstractTreeViewer.internalInitializeTree(AbstractTreeViewer.java:1527)

at org.eclipse.jface.viewers.TreeViewer.internalInitializeTree(TreeViewer.java:771)

at org.eclipse.jface.viewers.AbstractTreeViewer.lambda$1(AbstractTreeViewer.java:1512)

at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1447)

at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:354)

at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1408)

at org.eclipse.jface.viewers.CheckboxTreeViewer.preservingSelection(CheckboxTreeViewer.java:403)

at org.eclipse.jface.viewers.AbstractTreeViewer.inputChanged(AbstractTreeViewer.java:1506)

at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:286)

at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1685)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.scanProjects(MavenImportWizardPage.java:465)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage$1.widgetSelected(MavenImportWizardPage.java:183)

at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)

at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)

at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)

at org.eclipse.jface.window.Window.open(Window.java:794)

at org.eclipse.ui.internal.handlers.WizardHandler$Import.executeHandler(WizardHandler.java:158)

at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:290)

at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:291)

at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:92)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)

at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:305)

at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:239)

at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)

at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)

at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)

at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)

at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)

at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:390)

at org.eclipse.ui.internal.actions.CommandAction.runWithEvent(CommandAction.java:151)

at org.eclipse.ui.internal.actions.CommandAction.run(CommandAction.java:161)

at org.eclipse.ui.actions.ImportResourcesAction.run(ImportResourcesAction.java:99)

at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)

at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)

at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)

at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)

at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)

at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)

at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)

at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)

at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)

at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)

at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)

at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)

at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)

at org.eclipse.equinox.launcher.Main.run(Main.java:1499)

 

!ENTRY org.eclipse.ui 4 0 2019-09-16 14:33:23.656

!MESSAGE Unhandled event loop exception

!STACK 0

java.lang.NullPointerException

at org.eclipse.m2e.core.project.ProjectImportConfiguration.cleanProjectNameComponent(ProjectImportConfiguration.java:109)

at org.eclipse.m2e.core.project.ProjectImportConfiguration.getProjectName(ProjectImportConfiguration.java:83)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.isAlreadyExists(MavenImportWizardPage.java:615)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.updateCheckedState(MavenImportWizardPage.java:592)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.setAllChecked(MavenImportWizardPage.java:582)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage.scanProjects(MavenImportWizardPage.java:468)

at org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage$1.widgetSelected(MavenImportWizardPage.java:183)

at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)

at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)

at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)

at org.eclipse.jface.window.Window.open(Window.java:794)

at org.eclipse.ui.internal.handlers.WizardHandler$Import.executeHandler(WizardHandler.java:158)

at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:290)

at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:291)

at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:92)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)

at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:305)

at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:239)

at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)

at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)

at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)

at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)

at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)

at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:390)

at org.eclipse.ui.internal.actions.CommandAction.runWithEvent(CommandAction.java:151)

at org.eclipse.ui.internal.actions.CommandAction.run(CommandAction.java:161)

at org.eclipse.ui.actions.ImportResourcesAction.run(ImportResourcesAction.java:99)

at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)

at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)

at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)

at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)

at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1150)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)

at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)

at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)

at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)

at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)

at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)

at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)

at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)

at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)

at org.eclipse.equinox.launcher.Main.run(Main.java:1499)

 

!ENTRY org.eclipse.m2e.logback.appender 2 0 2019-09-16 14:38:53.596

!MESSAGE Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

 

!ENTRY org.eclipse.m2e.logback.appender 2 0 2019-09-16 14:38:53.680

 

!MESSAGE Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

 

 

搜了一圈,说是Eclipse的插件问题导致的,可以把“.metadata”这个文件夹删掉,代价是项目需要重新导入。

我删了,依然不行。

另外,不仅项目项目需要重新导入,Eclipse配置也全部还原了。

无计可施的时候,我对比了一下之前的文件,发现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>
    

  <properties>
……

正常的项目这部分是下面这样的:

<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>com.shuimutong</groupId>
    <artifactId>testw</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>testwMavenWebapp</name>
    <url>http://maven.apache.org</url>

  <properties>
……

把配置补全,导入成功!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

关于Eclipse导入maven项目报空指针异常

 

上一篇:数据传输结构Protobuf学习资料积累


下一篇:自定义事件派发机制