Java“XXX 已在 main 中定义”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2367757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java "XXX is already defined in main" error
提问by David
here is the program: (the file name is date.java)
这是程序:(文件名是date.java)
class date {
public static void main (String[] args) {
int day, hour, minute;
String firstline, half;
firstline="the current imaginary time is:";
day=24;
hour=5;
minute=36;
String half;
half="PM" ;
System.out.println ("here is some program about the time kindof:");
system.out.print (firstline) ;
system.out.print (day) ;
system.out.print (hour) ;
system.out.print (":") ;
system.out.print (minute) ;
system.out.println (half) ;
}
}
here is what happens when i try to compile it in terminal:
这是我尝试在终端中编译它时发生的情况:
david-allenders-macbook-pro:~ davidallender$ javac date.java
date.java:11: half is already defined in main(java.lang.String[])
String half;
^
date.java:15: package system does not exist
system.out.print (firstline) ;
^
date.java:16: package system does not exist
system.out.print (day) ;
^
date.java:17: package system does not exist
system.out.print (hour) ;
^
date.java:18: package system does not exist
system.out.print (":") ;
^
date.java:19: package system does not exist
system.out.print (minute) ;
^
date.java:20: package system does not exist
system.out.println (half) ;
^
7 errors
david-allenders-macbook-pro:~ davidallender$
im learning from a book i found online. right now i'm in the chapter about variables. What did i do wrong?
我从网上找到的一本书中学习。现在我在关于变量的章节中。我做错了什么?
回答by objects
String half;
you have already declared half earlier, remove this one
你之前已经声明了一半,删除这个
system.out.print (firstline) ;
Class names in java are case sensitive. system should be System
java中的类名区分大小写。系统应该是系统
回答by brian
Remove the second 'String half;' in main. And system should be System.
删除第二个 'String half;' 在主要。而系统应该是系统。
回答by fastcodejava
Variables can be declared once in any scope and it is Systemnot system.
变量可以在任何范围内声明一次,它System不是系统。
回答by Jason
You may want to try the Eclipse Java IDE (Integrated Development Environment) so that you can avoid these problems in the future. It will suggest fixes to these sort of simple errors.
您可能想尝试 Eclipse Java IDE(集成开发环境),以便将来避免这些问题。它将建议修复这些简单的错误。
http://www.eclipse.org/downloads/
http://www.eclipse.org/downloads/
Plus, it's free!
另外,它是免费的!

