简体   繁体   English

Android Studio无法识别String

[英]Android Studio not recognizing String

I've encountered a weird glitch in Android Studio: 我在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 我正在运行适用于Mac的Android Studio 0.5.8

Things I've tried so far: 到目前为止我尝试过的事情:

  • Restart Android Studio 重启Android Studio
  • Restart MacBook 重启MacBook
  • Invalidate caches and restart 使缓存无效并重新启动
  • tried other strings (like "en-US" this result in the same effect) 尝试过其他字符串(比如“en-US”这个结果效果相同)

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. IntelliJ和Android Studio能够获取字符串参数并将字符串视为另一种语言。 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. 例如,如果您有一个采用HTML字符串的方法,如果您告诉IDE它,它可以为您提供语法突出显示和内容辅助,以及该字符串中的HTML。

I think you've inadvertently set this string as being treated as Java, and it's giving you the Java syntax errors on it. 我认为你无意中将这个字符串设置为Java,它会给你带来Java语法错误。 You need to un-set that setting. 您需要取消设置该设置。 Select the text, bring up the Search Action feature (on Mac it's shift a ). 选择文本,调出搜索动作功能(在Mac上是 )。 In the search box that comes up, search for Un-inject Language/Reference, as shown in the screenshot below: 在出现的搜索框中,搜索Un-inject Language / Reference,如下面的屏幕截图所示:

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

试试这个

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

Since Android Studio is a bit raw, you can face the "glitches" in many different ways. 由于Android Studio有点原始,你可以通过许多不同的方式面对“故障”。 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 继续使用AS并忽略这些奇怪的事情,希望他们能够发布一次强大的软件
  2. Or, to migrate to IntelliJ IDEA as I did. 或者,像我一样迁移到IntelliJ IDEA。 The procedure is pricey but it's worth it. 这个程序很昂贵,但值得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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