0

I am getting this error "stray '\302' in program ", while I am using this following line of code:

[UIButton setAnimationDuration:1.0];

How can I resolve this error?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user944329
  • 11
  • 1
  • 1
  • 1
    You should also not use `+[UIButton setAnimationDuration:]`. The view-animation methods (beginAnimation, commitAnimation,..) are class methods of `UIView`. `UIButton` does inherit from `UIView`, so this code will work, but since the animation not only affects `UIButton`s but all `UIView`s, your code will be clearer and more understandable when you use `+[UIView setAnimationDuration:]` etc. – Ahti Sep 29 '11 at 13:38
  • You should probably accept an answer, add one of your own or delete this question. It will increase the likelihood of others helping you in the future. – Hyperbole Oct 05 '11 at 21:27
  • Isn't there a second stray error, \240? That would make for the very common Unicode code point U+00A0 ([NO-BREAK SPACE](https://www.charset.org/utf-8)), UTF-8 sequence 302 240 (octal), 0xC2 0xA0 (hexadecimal). It can be searched for (and replaced) by regular expression `\x{00A0}` in any modern text editor or IDE (but it isn't in the posted source code). (Note: The notation is different in Visual Studio Code (and probably others): `\u00A0` (instead of `\x{00A0}`).) – Peter Mortensen Apr 30 '23 at 03:07
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 30 '23 at 03:08

3 Answers3

0

\302 is an unprintable character which is somewhere in the your code near or on the line that you receive the error.

Just delete al empty, tabs and spaces it should solve your problem.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
0

It’s right here:

` `

Just a joke. If the above suggestion fails you, perhaps opening the file in another editor that allows you to show all nonprintable characters. Perhaps even Xcode has this feature. TextWrangler does if you have no other available.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
EricLeaf
  • 892
  • 5
  • 12
0

Things like this happen when you copy/paste code from the Internet. Delete the affected line and retype it by hand in Xcode and the problem should disappear.

In the future, be aware of things like this slipping in to your code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hyperbole
  • 3,917
  • 4
  • 35
  • 54