Java编译错误

发布于 2024-12-01 20:03:08 字数 1149 浏览 0 评论 0原文

我在尝试编译代码时遇到了问题:

D:\workspace>javac DbConnect.class
javac: invalid flag: DbConnect.class
Usage: javac <options> <source files>
use -help for a list of possible options

这就是我得到的。事实上,我从未添加过任何这些选项,而且它对我来说一直工作得很好。我可能做错了什么?

编辑:

谢谢大家,在办公室度过了漫长的一天:)

当我从 Eclipse 中触发代码时,代码工作正常。如果我输入 java DbConnect.class 我会收到此错误。

D:\workspace\GeoCoding\bin\de\bitmarck\bi>java DbConnect.class
Exception in thread "main" java.lang.NoClassDefFoundError: DbConnect/class
Caused by: java.lang.ClassNotFoundException: DbConnect.class
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: DbConnect.class.  Program will exit.

它可以在 Eclipse 中运行,但似乎不喜欢手动启动。
类中有一个main
我做错了什么?

I'm running into a problem while trying to compile my code:

D:\workspace>javac DbConnect.class
javac: invalid flag: DbConnect.class
Usage: javac <options> <source files>
use -help for a list of possible options

This is what i get. I actually have never added any of those options and it always worked fine for me. What could i have done wrong ?

EDIT:

Thanks guys it has been a long day at the office :)

The code works fine when i fire it from eclipse. If i type java DbConnect.class i get this Error.

D:\workspace\GeoCoding\bin\de\bitmarck\bi>java DbConnect.class
Exception in thread "main" java.lang.NoClassDefFoundError: DbConnect/class
Caused by: java.lang.ClassNotFoundException: DbConnect.class
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: DbConnect.class.  Program will exit.

It works in Eclipse but it just doesn't seem to like being started manually.
There is a main in the class.
What am i doing wrong ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吲‖鸣 2024-12-08 20:03:08

尝试

javac DbConnect.java 

编译(文件扩展名是 .java 而不是 .class )

java DbConnect

运行它,如果这是您需要的

try

javac DbConnect.java 

to compile ( the file extension is .java not .class )

or

java DbConnect

to run it, if that's what you need

演出会有结束 2024-12-08 20:03:08

试试这个:

  1. 编译:D:\workspace>javac DbConnect.java

  2. 运行:D:\workspace>java DbConnect

Try this:

  1. To Compile : D:\workspace>javac DbConnect.java

  2. To Run: D:\workspace>java DbConnect

他夏了夏天 2024-12-08 20:03:08

您尝试编译已经编译的类(它具有 .class 扩展名)。

You try to compile already compiled class (it has .class extension).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文