NullPointerException 当我尝试在 Eclipse 上访问我的 API 时,但它正在 IntelliJ 上工作



我的API有问题。对于我的一个学校项目,我需要在 Eclipse 工作区中发送我的项目。但我在IntelliJ上编码了它,因为我更喜欢它。当我想在 Eclipse 上传递我的代码时,该项目不起作用,所以我创建了一个新项目并将我的代码放入其中。但是目前,我无法访问此API,因为我有一个nullPointerException。nullPointerException在我的DAO上,在IntelliJ上它正在工作。所以错误是:

Servlet.service() for servlet access.RestApplication threw exception
java.lang.NullPointerException
at model.dao.DaoComment.getAll(DaoComment.java:150)
at access.CommentAPI.getAll(CommentAPI.java:28)
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)

DAO是这样的:

@Override
public List<User> getAll() {
CallableStatement stmt = null;
List<User> users = new ArrayList<>();
ResultSet resultSet = null;
try {
  stmt = connect.prepareCall("{? = call USERPACKAGE.getAll}");
  stmt.registerOutParameter(1, OracleTypes.CURSOR);
  stmt.execute();
  resultSet = (ResultSet) stmt.getObject(1);
  if (resultSet != null) {
    while (resultSet.next()) {
      User u = new User();
      u.setId(resultSet.getInt(1));
      u.setEmail(resultSet.getString(2));
      u.setPassword(resultSet.getString(3));
      u.setFirstname(resultSet.getString(4));
      u.setLastname(resultSet.getString(5));
      u.setAddress(resultSet.getString(6));
      u.setBirthday(resultSet.getTimestamp(7));
      u.setRegisterDate(resultSet.getTimestamp(8));
      u.setRelationship(resultSet.getInt(9) == 1);
      u.setPhoneNumber(resultSet.getInt(10));
      u.setGender(resultSet.getInt(11) == 1);
      u.setInterestedIn(resultSet.getInt(12) == 1);
      users.add(u);
    }
  }
} catch (SQLException e) {
  e.printStackTrace();
  return null;
} finally {
  if (stmt != null) {
    try {
      stmt.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  if (resultSet != null) {
    try {
      resultSet.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
return users;

通常,在它之后,我获取数据并通过json发送,但在这里它不起作用。异常堆栈跟踪为:

java.util.MissingResourceException: Can't find bundle for base name sun.util.logging.resources.logging, locale en_US
at java.base/java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.base/java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.base/java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.base/java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.base/java.util.ResourceBundle.getBundle(Unknown Source)
at org.eclipse.glassfish.tools.log.LevelResolver.getLocalized(LevelResolver.java:49)
at org.eclipse.glassfish.tools.log.LevelResolver.<init>(LevelResolver.java:31)
at org.eclipse.glassfish.tools.log.AbstractLogFilter.<init>(AbstractLogFilter.java:36)
at org.eclipse.glassfish.tools.log.PatternLogFilterV4.<init>(PatternLogFilterV4.java:32)
at org.eclipse.glassfish.tools.log.AbstractLogFilter.createFilter(AbstractLogFilter.java:75)
at org.eclipse.glassfish.tools.log.GlassfishConsoleManager.getStandardConsole(GlassfishConsoleManager.java:53)
at org.eclipse.glassfish.tools.GlassfishServerLaunchDelegate$2.run(GlassfishServerLaunchDelegate.java:390)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:37)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:182)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3906)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3537)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1170)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1059)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:667)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
at org.eclipse.equinox.launcher.Main.main(Main.java:1471)

MissingResourceException 指出您缺少资源包。
只需将文件sun/util/logging/resources/logging_en_US.properties添加到项目中即可。
内容应如下所示:

# Localizations for Level names.  For the US locale
# these are the same as the non-localized level name.
# The following ALL CAPS words should be translated.
ALL=All
# The following ALL CAPS words should be translated.
SEVERE=Severe
# The following ALL CAPS words should be translated.
WARNING=Warning
# The following ALL CAPS words should be translated.
INFO=Info
# The following ALL CAPS words should be translated.
CONFIG= Config
# The following ALL CAPS words should be translated.
FINE=Fine
# The following ALL CAPS words should be translated.
FINER=Finer
# The following ALL CAPS words should be translated.
FINEST=Finest
# The following ALL CAPS words should be translated.
OFF=Off

另请参阅此堆栈溢出答案