简体   繁体   中英

Android Studio not recognizing String

I've encountered a weird glitch in Android Studio: Android studio String故障

As you can see it thinks that it is an error:

'class' or 'interface' expected

But it runs and build just fine, so is this just a visual glitch or can it have any effect during compiling?

I'm running Android Studio 0.5.8 for Mac

Things I've tried so far:

  • Restart Android Studio
  • Restart MacBook
  • Invalidate caches and restart
  • tried other strings (like "en-US" this result in the same effect)

If I use a string through the resources the glitch isn't visible (which it will be eventually, I'm just curious why this is happening)

IntelliJ and Android Studio have the ability to take string parameters and treat the strings as being in another language. For example, if you have a method that takes a string that's HTML, if you tell the IDE about it, it can give you syntax highlighting and content assist with the HTML in that string.

I think you've inadvertently set this string as being treated as Java, and it's giving you the Java syntax errors on it. You need to un-set that setting. Select the text, bring up the Search Action feature (on Mac it's shift a ). In the search box that comes up, search for Un-inject Language/Reference, as shown in the screenshot below:

IDE的屏幕截图,显示搜索取消注释语言/引用的命令

试试这个

httpReqquest.addHeader("Accept-Language","en-US");

Since Android Studio is a bit raw, you can face the "glitches" in many different ways. They're annoying but don't affect the result, as you said. However, I personally don't think that we should endure the inconveniences (even if the Studio costs nothing).

I see a couple of solutions:

  1. Continue with AS and ignore these weird things, hoping they will release a robust software once
  2. Or, to migrate to IntelliJ IDEA as I did. The procedure is pricey but it's worth it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM