Android Studio充满错误

Dav*_*las 4 android manifest gradle android-manifest android-gradle-plugin

好的,因此我无法按照Android Studio的要求进行任何开发。我的所有项目到处都是错误,这些错误由Android Studio引起。

注意:我的文件是正确的,这是另一个问题,因为即使我从google代码中导入某些内容也会出错。

当我导入一个项目时,一切都很好,但是在建立索引等之后,所有突然的事情都是红色的,不应该这样。

我的错误例如是:

 button1.setOnLongClickListener(new View.OnLongClickListener()

{
 .... 
  ....
}
Run Code Online (Sandbox Code Playgroud)

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

另一个例子:

    button1=(Button) findViewById(R.id.button1);
Run Code Online (Sandbox Code Playgroud)

我将这个确切的代码用于其他按钮,似乎是正确的,我一直使用此行,直到我的Android Studio决定给我一些辛苦的时间,这行很好,此行充满了错误,它们是:

Unknown class: 'button1' , invalid method declaration; return type required, missing method body, or declare abstract
Run Code Online (Sandbox Code Playgroud)

我尝试了20种不应该发生的错误:

  1. 删除iml文件,.idea文件夹-工作了一段时间,但现在又发生了一次,但无法解决。
  2. 重新安装android studio,然后导入项目。
  3. 将android studio版本升级到1.3
  4. 重新启动我的电脑。
  5. 将项目导入另一台PC,过了一会儿。
  6. 使缓存无效/重新启动。
  7. 更改项目结构中的模块-我将其更改回原来的状态(这无济于事),我认为这导致清单错误降低。

我的模块: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'
    }
Run Code Online (Sandbox Code Playgroud)

我现在也注意到,清单文件中的一个错误android:name=".MainActivity"表示它没有默认结构。这样的事情。这是完整的普通代码:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

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

Som*_*ere 5

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

要解决这个问题:

  • 单击文件>取消缓存/重新启动
  • 然后关闭项目
  • 重新打开项目

在此处输入图片说明

  • 我必须做的另一件事是在关闭项目后删除项目中的 `.gradle` 和 `.idea` 文件夹。当您再次打开项目时,Android Studio 会显示错误并修复它。 (2认同)
  • 使缓存无效/重新启动,并删除 .gradle 和 .idea 文件夹对我有用 (2认同)