aspose file tools
The moose likes Beginning Java and the fly likes indexOf() error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "indexOf() error" Watch "indexOf() error" New topic
Author

indexOf() error

Momo Sawada
Greenhorn

Joined: Dec 10, 2010
Posts: 24
hello once again... i have a problem with my indexOf method.... i dont know why... it said in the API i can use it with the util. package.. but it doesn't run... can anyone help me please???
its at line 67...
codecodecode:


thank you very much!!!
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Where did you declare your indexOf(..) method?

Or should it actually be link.indexOf(..)?

Sean


I love this place!
Momo Sawada
Greenhorn

Joined: Dec 10, 2010
Posts: 24
at line 67... i tried using it to get the index of the found element and replacing it with another in the same index....
Javad Rashidi
Ranch Hand

Joined: Feb 13, 2011
Posts: 34

you invoke this method on an String object. where is your String?


http://www.myviwo.com
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9956
    
    6

Momo Sawada wrote:at line 67... i tried using it to get the index of the found element and replacing it with another in the same index....

on line 67, you CALL the indexOf() method, not declare it. If you call a method by simply typing the name, Java assumes you are trying to call a method defined in the current class. If you are trying to call the String class' indexOf method, you need to call it on a specific String.

What String is your 'r' supposed to be a substring of? you would need to change 67 to something like

int indx=myString.indexOf(r);

and replace 'myString' with whatever String you are searching.


Never ascribe to malice that which can be adequately explained by stupidity.
Momo Sawada
Greenhorn

Joined: Dec 10, 2010
Posts: 24
oh... i see... thank you!!! i finally had my program running!!! Thank you very much!!!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9956
    
    6

glad we could help!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32712
    
    4
Beware of long lines in code tags; they are difficult to read. And only use spaces for indentation, not tabs.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: indexOf() error
 
Similar Threads
Help correcting a button behavior in swing
Ready to give up!
Swing/Applet question
Display an array in a swing type box