-2

I am trying to make a java script for a mobile app check if a string contains specific characters.

if(fn.contains(" ")){

}

The fn variable is declared twice in the following:

private EditText fn;
final EditText fn = (EditText) findViewById(R.id.fn);

Not sure why this doesn't work. In android studio, the contains function highlights red as it doesn't exist. You can click here to see what I am talking about. Is there another method than this?

msrd0
  • 7,816
  • 9
  • 47
  • 82
That1nub
  • 11
  • 5
  • Include the declaration of `fn` in the post, and ensure you aren't shadowing the `String` type – Vince Oct 21 '17 at 20:53
  • Java doesn't have scripts. – Neo Oct 21 '17 at 20:54
  • 1
    Java and JavaScript are two different languages. https://stackoverflow.com/questions/1789945/how-to-check-whether-a-string-contains-a-substring-in-javascript – KALALEX Oct 21 '17 at 20:54
  • @KALALEX He never said JavaScript. He said a Java script (a script written in Java) – Vince Oct 21 '17 at 22:24

1 Answers1

0

That is an EditText not a string you must do first:

var str = fn.getText().toString()

if(str.indexOf(" ") !== -1;){ . . . }
KALALEX
  • 430
  • 1
  • 5
  • 19