File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes I don't understand - why this compile error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I don Watch "I don New topic

I don't understand - why this compile error?

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
When I compile either of these 2 versions of I get a compile error using a string literal. Why? The 2 versions are:
public class Gary
static public void main(String args[])
String tmp = "boy";
OR version 2 below:
public class Gary
static public void main(String args[])
String tmp = new String();
tmp = "boy";

Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Both of them work, are you sure about the compiler error?
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Both of these compile with no error for me.
What error did you get?

"JavaRanch, where the deer and the Certified play" - David O'Meara
Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
The compile error I get on both versions is:
Incompatible type for declaration. Can't convert java.lang.string to string.
Any idea why I'm getting this & you're not?
Andy Ceponis
Ranch Hand

Joined: Dec 20, 2000
Posts: 782
Compiles fine for me as well. Not sure what it could be.
Paul Ralph
Ranch Hand

Joined: Aug 10, 2000
Posts: 312
Is there any way you could copy and post the code and error message? You may have already done this...grasping for straws :|
Paul R
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113
use 'String' instead of 'string' as your data type for strings...
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I am coming in quite late on this topic...
but I've had a very strange and similar experience.

If you are using TextPad as your Java editor, sometimes Textpad will *NOT* (it is VERY stubborn about it too) recognize a change in source file.

Most of the time it happens when I realize my class name is not capitalized, and I attempt to change it in the source, and 'save as' to make a new file. When I try to compile, it gives the error about classes needing to be named the same as the file name... and it gives the former lower case class name. The one that when you flip back to the source, is obviously TitleCase!!

I try everything I can, and it will just NOT recognize the changed source. I have tried shutting down Textpad, deleting all my temp directories, using TaskManager to kill anything suspicious, and still it gives an error. Believe it or not, it requires me to reboot my NT box. TextPad must have some sneaky temp location.

Has anyone else run across this very strange glitch?
I agree. Here's the link:
subject: I don't understand - why this compile error?
Similar Threads
String initialization
Why This Compiler Error?
What's This compile error?
Why This compile error?