Java编译错误
我在尝试编译代码时遇到了问题:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
编译(文件扩展名是 .java 而不是 .class )
或
运行它,如果这是您需要的
try
to compile ( the file extension is .java not .class )
or
to run it, if that's what you need
试试这个:
编译:
D:\workspace>javac DbConnect.java
运行:
D:\workspace>java DbConnect
Try this:
To Compile :
D:\workspace>javac DbConnect.java
To Run:
D:\workspace>java DbConnect
您尝试编译已经编译的类(它具有 .class 扩展名)。
You try to compile already compiled class (it has .class extension).