Android Studio 充满了错误

标签 android gradle android-gradle-plugin android-manifest manifest

好的,所以我不能像我的 Android Studio 决定的那样开发任何东西。 我的所有项目都充满了错误,Android Studio 导致的未知错误。

注意:我的文件是正确的,这是另一个问题,因为即使我从谷歌代码中导入一些东西,它也会有错误。

当我导入一个项目时一切正常,但是在索引和类似的事情之后,突然一切都是红色的,不应该是。

例如我的错误是:

 button1.setOnLongClickListener(new View.OnLongClickListener()

{
 .... 
  ....
}

应该不是错误但是:cannot resolve symbol setOnLongClickListener

另一个例子:

    button1=(Button) findViewById(R.id.button1);

我为其他按钮使用了这个确切的代码,似乎是正确的,我一直使用这一行,它很好,直到我的 Android Studio 决定给我一些困难,这一行充满了错误,它们是:

Unknown class: 'button1' , invalid method declaration; return type required, missing method body, or declare abstract

并且有大约 20 个不应该出现的错误,我尝试过的事情:

  1. 删除 iml 文件、.idea 文件夹 - 工作了一段时间,但现在又发生了,但无法修复。
  2. 重新安装 android studio,然后导入项目。
  3. 正在将 android studio 版本升级到 1.3
  4. 重新启动我的电脑。
  5. 将项目导入另一台电脑,发生在一段时间后。
  6. 使缓存无效/重新启动。
  7. 更改项目结构中的模块 - 我将其改回原来的样子(没有帮助),我认为它导致了 list 错误......

我的模块:app build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion '22.0.1'

defaultConfig {
    applicationId "firstappdevelopments.david.reactiontime"
    minSdkVersion 9
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
     }
}

  dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:22.2.1'
    }

我现在还注意到,我的 Manifest 文件在 android:name=".MainActivity" 中作为错误表示它没有默认结构。像这样的东西。这是完整的正常代码:

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

</manifest>

请,如果有人知道问题是什么或我还能做什么,请说,我对我的英语感到抱歉,谢谢大家。

最佳答案

我所看到的是我的代码充满了错误,但它仍然可以正常构建并且可以很好地部署到设备上。

修复它:

  • 单击"file">“使缓存无效/重新启动”
  • 然后关闭项目
  • 重新打开项目

enter image description here

关于Android Studio 充满了错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31792393/

相关文章:

android - 如何检测android中的顺时针手势

json - 使用Gradle,如何仅将Play框架的JSON库列出为依赖项?

spring-boot - 字段存储库需要找不到名为 'entityManagerFactory'的bean

android - 错误 :Unable to find method 'com. android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;安卓工作室 3

java - Android - 通过数组在点之间绘制线

android - RelativeLayout 比 LinearLayout 贵吗?

android - fragment后台任务访问资源经常返回illegalStateException

java - 添加 Play Services 依赖项会导致与 Firebase 发生冲突

android - google-services.json 文件已添加,但模块根文件夹中缺少 : File google-services. json 错误

android - IntelliJ IDEA中包含什么Android插件版本?