aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes IntelliJ Idea IDE not supporting String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "IntelliJ Idea IDE not supporting String" Watch "IntelliJ Idea IDE not supporting String" New topic
Author

IntelliJ Idea IDE not supporting String

John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Using Idea, when I code

String abc = "abc";

abc.substring(0);

substring is colored red with the error message

cannot resolve symbol substring.

when abc. is coded,

a list of methods is displayed which includes

equals, hashcode, notify, notifyAll, toString, 3 signatures of wait.

substring, and trim should be part of this list. Why aren't these methods of String supported by Idea? I don't have a problem with this using Eclipse.
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by John Davis:
Using Idea, when I code

String abc = "abc";

abc.substring(0);

substring is colored red with the error message

cannot resolve symbol substring.

when abc. is coded,

a list of methods is displayed which includes

equals, hashcode, notify, notifyAll, toString, 3 signatures of wait.

substring, and trim should be part of this list. Why aren't these methods of String supported by Idea? I don't have a problem with this using Eclipse.



When I code this in IntelliJ 5.1, I get a nice green light w/ no errors:



I wonder what's different?


%
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Its weird, but one thing is different. I am using IntelliJ 3.0.5
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, two possibilities. One is that you've gone and defined your own class named "String", and IntelliJ is finding it. This happens more often than you would think!

The other possibility is that you've got IntelliJ configured to compile against a JDK library that doesn't exist -- the path is wrong, for example.

Either of these could cause behavior like that.


[Jess in Action][AskingGoodQuestions]
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Ernest,
Thanks for your interest and help, but this situation just gets "curiouser and curiouser".
2 possibilities:
I don't have my own String class.
I tried switching to different versions JDKs - same results.

The reason I say "curiouser and curiouser" is that I can compile and run the program (which does a substring and prints it). The situation is that if I try to use any methods not in the drop down auto complete list, they are highlighted in red and IntelliJ complains that it doesn't know what it is, but these statements compile and run without error. It looks more and more to me like an IDE error.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Check your Module Settings dialog on the "Libraries" tab, Target JDK. If the Target JDK is printed in red, you're referencing a JDK that you may have uninstalled (thus it can't find the classes).

Although usually you get a lot of slop because java.lang.Object won't be defined either.

I don't know if it's available in IntelliJ 3, but in 5.0, hovering the mouse over "String" and pressing the Ctrl key will cause info to popup. If it doesn't say "java.lang.String" you know you've got a naming conflict.


Customer surveys are for companies who didn't pay proper attention to begin with.
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Tim,

Thanks for your interest and reply.

I checked String in my code and it is indeed java.lang.String

I also checked my JDK settings for the project within IntelliJ and found no red markings. The JDK I am using has not been uninstalled. I used Explorer to check this out and everything required for a JDK installation is present.

I also checked several different JDK settings for JDKs which have been installed on my machine, and I got the same result for all of them.

John Davis
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

On a hunch, I tried this in IDEA 5.0.2:



And sure enough, the word "substring" lights up red, and the tooltip says "Cannot resolve symbol 'substring'." If I try to do autocompletion on abc., I do actually get the full list of String methods, though -- perhaps this is explainable by the version difference.

Anyway, yes, it's a bad error message, but this code is quite wrong: you can't put an expression like "abc.substring(0)" at class scope. It has to be inside a method, constructor, or initializer block.



So John, is this the problem?
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
Ernest,

No, that isn't the problem.

To be accurate, my problem is with the indexOf method of string and it lights up red every time (and its coded within a method).



But actually, looking at this code again precipitated an idea. You may have noticed that the method the indexOf is coded within is a action callback method and the app I am developing is a Swing app. I'm now guessing that somehow this is at the source of the problem although I don't know what to do to fix it.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

If you right-click on "queueName" and say "Go To Declaration", does it go where you expect? Perhaps there are two "queueNames" in effect here.
John Davis
Ranch Hand

Joined: Nov 02, 2000
Posts: 189
right clicking on queueName and going to the declaration repositions the cursor to


which is in the same method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: IntelliJ Idea IDE not supporting String