File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I don't understand - why this compile error?

 
Gary Farms
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile either of these 2 versions of Gary.java I get a compile error using a string literal. Why? The 2 versions are:
Version1:
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
Posts: 688
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of them work, are you sure about the compiler error?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of these compile with no error for me.
What error did you get?
 
Gary Farms
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiles fine for me as well. Not sure what it could be.
 
Paul Ralph
Ranch Hand
Posts: 313
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 113
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use 'String' instead of 'string' as your data type for strings...
later
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic