string cannot be resolved to a type
14,021
String
is capitalized in Java. You cannot use lowercase string
. (That's C#)
Side question:
How is the following compiling at all?
template.composeFormLetter(Sean, Colbert, God);
Related videos on Youtube
Author by
chief
Updated on June 04, 2022Comments
-
chief almost 2 years
I am getting a "string cannot be resolved to a type" error in my code.
public class Main { public static void main(String[] args) { // TODO Auto-generated method stub FormLetter template; template = new FormLetter(); template.print(); template.composeFormLetter(Sean, Colbert, God); template.print(); } } class FormLetter { public void print(){ System.out.println(to + candidate + from); } public void composeFormLetter(string t, string c, string f){ to = t; candidate = c; from = f; } private string to; private string candidate; private string from; }
-
In silico over 13 yearsFor future reference, be sure to post the entire compiler error message in your question if present, to make it easier to pinpoint what's wrong.
-
-
chief over 13 yearsOk, I corrected the string issue. template.composeFormLetter(Sean, Colbert, God); is leaving an error: Multiple markers at this line - God cannot be resolved - Colbert cannot be resolved - Sean cannot be resolved
-
Stephen C over 13 years@chief - String literals are supposed to have double quotes around them. (Side answer - it is not ...)
-
jjnguy over 13 years@chief,
"God"
,"Sean"
,"Colbert"
You need to putStrings
inside of quotation marks. -
chief over 13 yearsAlright in the console it returns: nullnullnull and then god colbert sean.
-
jjnguy over 13 years@chief, that's what it's supposed to do?
-
chief over 13 yearsgod colbert sean - is what I was expecting. I am not sure why I am also getting nullnullnull first.
-
jjnguy over 13 years@chief, Well, you call
template.print()
twice. The first time all of the variables arenull
, and the second time they have values. -
jjnguy over 13 years@chief, also, you should check the green checkmark next to my answer to show that it is the one that helped you answer your question.