aspose file tools*
The moose likes Beginning Java and the fly likes indexOf() error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 11475
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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: 11475
    
  16

glad we could help!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
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://aspose.com/file-tools
 
subject: indexOf() error