• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

indexOf() error

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Rancher
Posts: 377
Android Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you declare your indexOf(..) method?

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

Sean
 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at line 67... i tried using it to get the index of the found element and replacing it with another in the same index....
 
Ranch Hand
Posts: 34
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you invoke this method on an String object. where is your String?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Momo Sawada
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh... i see... thank you!!! i finally had my program running!!! Thank you very much!!!
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
glad we could help!
 
Marshal
Posts: 79707
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beware of long lines in code tags; they are difficult to read. And only use spaces for indentation, not tabs.
 
Screaming fools! It's nothing more than a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic