Reputation: 31
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.
the program is supposed to print hello world on to the screen. here is my attempt at it:
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!!
Upvotes: 1
Views: 47301
Reputation: 1
If possible, the class name should start with a capital letter, and the first letter of the word that appears after it should also be capitalized.
Upvotes: -1
Reputation: 154
Remember in Java, String is a Class or Simply Object. Class names always start with Capital Letters in Java. So, string should be String.
Upvotes: 0
Reputation: 1
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".
Upvotes: 0
Reputation: 3641
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");
}
}
Upvotes: 1
Reputation: 346506
"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.
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.
When you get this error the typical reasons are:
Upvotes: 0
Reputation: 19304
Use String
not string.
public static void main(String[] args) { System.out.println("hello eclipse"); }
Java classes are case sensitive. String
is the class you need.
Upvotes: 5