java 无法解析为类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16786168/
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
Cannot be resolved to a type?
提问by Jordan Holland
So I have been programming for all of 4 hours, I am using a this tutorial http://www.vogella.com/articles/Eclipse/article.html#eclipseoverview. when after copying the code I got an error cannot be resolved to a type. I then did what all my friends told me to do, look at the code. I spent an hour making sure mine looked like his.
所以我一直在编程 4 个小时,我正在使用本教程 http://www.vogella.com/articles/Eclipse/article.html#eclipseoverview。复制代码后出现错误无法解析为类型。然后我按照我所有朋友告诉我的去做,看看代码。我花了一个小时确保我的看起来像他的。
the program is supposed to print hello world on to the screen. here is my attempt at it:
该程序应该将 hello world 打印到屏幕上。这是我的尝试:
package de.vogella.eclipse.ide.first;
public class myFirstClass {
public static void main(string[] args) {
System.out.println("hello eclipse");
}
}
In eclipse the word string is highlighted and it says that it cant be resolved to a type. I have also tried another java tutorial, Java total beginners, and this same problem appears. Any help would be appreciated, I'm totally new to programming, I try to learn more by using tutorials but this keeps stopping me (i know catch 22. Any advice that could help me get past this would be great, advice or maybe a question that already covered this any help would be great!!
在 eclipse 中,单词 string 被突出显示,并表示它无法解析为类型。我也试过另一个java教程,java总初学者,出现了同样的问题。任何帮助将不胜感激,我对编程完全陌生,我尝试通过使用教程来学习更多,但这一直阻止我(我知道第 22 条。任何可以帮助我克服这个问题的建议都会很棒,建议或者可能是已经涵盖了这一点的问题任何帮助都会很棒!!
回答by BobTheBuilder
Use String
not string.
使用String
非字符串。
public static void main(String[] args) { System.out.println("hello eclipse"); }
Java classes are case sensitive. String
is the class you need.
Java 类区分大小写。String
是你需要的课程。
回答by Adarsh
public class myFirstClass {
public static void main(string[] args) {
System.out.println("hello eclipse");
}
}
should be
应该
public class myFirstClass {
public static void main(String[] args) {
System.out.println("hello eclipse");
}
}
回答by Michael Borgwardt
"cannot be resolved to a type" means that the compiler has decided that, according to the syntax of the language, what it found at this place in the code has to be type, which means either a class, an interface, or a primitive tpye, but cannot find the definition of any type with that name.
“无法解析为类型”意味着编译器已经决定,根据语言的语法,它在代码中的这个地方找到的东西必须是类型,这意味着要么是类,要么是接口,要么是基元tpye,但找不到具有该名称的任何类型的定义。
In this case, "string" cannot be resolved because there is no such type - Java is case sensitive, and the class is named String. There is an extremely strong convention for class names to start with an uppercase letter. The only lowercase types you'll normally encounter are the primitive types like int and boolean.
在这种情况下,“string”无法解析,因为没有这样的类型 - Java 区分大小写,并且类名为 String。类名以大写字母开头有一个非常严格的约定。您通常会遇到的唯一小写类型是原始类型,如 int 和 boolean。
When you get this error the typical reasons are:
当您收到此错误时,典型原因是:
- you mistyped the name of the type
- or the package in the import statement is wrong
- or you have a problem with the classpath.
- 你打错了类型的名称
- 或者import语句中的包错误
- 或者你的类路径有问题。
回答by Pranit
As per the Java language Specification the signature of main() method takes a parameter of String array. As Java is case sensitive and there is no such type/class called "string" thus it is giving you the said error. We have "String" as a class in java which should be present over there as "String[] args".
根据 Java 语言规范,main() 方法的签名采用 String 数组的参数。由于 Java 区分大小写,并且没有这样的类型/类称为“字符串”,因此它会给您上述错误。我们有“String”作为java中的一个类,它应该作为“ String[] args”出现在那里。
回答by Apeal Tiwari
Remember in Java, String is a Class or Simply Object. Class names always start with Capital Letters in Java. So, string should be String.
请记住,在 Java 中,String 是一个类或简单的对象。在 Java 中,类名总是以大写字母开头。所以,字符串应该是字符串。