gpt4 book ai didi

java - 当我尝试在 Eclipse 上访问我的 API 但它在 IntelliJ 上运行时出现 NullPointerException

转载 作者:行者123 更新时间:2023-11-30 05:49:45 26 4
gpt4 key购买 nike

我的 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

另请参阅this stackoverflow answer

关于java - 当我尝试在 Eclipse 上访问我的 API 但它在 IntelliJ 上运行时出现 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54137392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com