Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio is full of errors

Okay, so I can't develop nothing as my Android Studio decided to. My all project is full of errors, unknown errors caused by Android Studio.

note: my files are correct, it is an other problem because even if I will import something from google codes it will have errors.

When I import a project everything's fine, but then after indexing and such things, all sudden everything is red and shouldn't be.

My errors for example are :

 button1.setOnLongClickListener(new View.OnLongClickListener()

{
 .... 
  ....
}

Well shouldn't be error but : cannot resolve symbol setOnLongClickListener

Another example:

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

I used this exact code for other button, seems right, I always using this line, it was fine until my Android Studio decided to give me some hard time, this line is full by errors and they are:

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

and there are like 20 errors that shouldn't be, things I tried:

  1. deleting iml files , .idea folder - worked for a while but now it happened again and it doesn't fix it.
  2. reinstalling android studio and then importing project.
  3. upgrading android studio version to 1.3
  4. restarting my pc.
  5. importing project to an other pc, happened after a while.
  6. Invalidate caches/ restart.
  7. Changing module in project structure - I changed it back to how it was (it didn't help) and I think it caused the manifest error down..

My Module: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'
    }

Also I noticed now, my Manifest file as an error in android:name=".MainActivity" says it has no default structure. something like this. here is the full normal code:

<?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>

Please, if someone knows what is the problem or what can I else do, just say, and I am sorry about my English, thank you all.

like image 351
DavidBalas Avatar asked Aug 03 '15 16:08

DavidBalas


2 Answers

What I've seen is my code is full of errors, but it still builds fine and deploys fine to the device.

To fix it:

  • click on FILE > INVALIDATE CACHES / RESTART
  • Then close the project
  • Re open the project

enter image description here

like image 179
Someone Somewhere Avatar answered Nov 11 '22 08:11

Someone Somewhere


For me I upgraded my Kotlin Version from 1.4 to 1.5.0 and it is now working.

dependencies {
    classpath 'com.android.tools.build:gradle:4.2.1'
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

Afterwards I did a clean and a Rebuild and everything worked fine thereafter.

like image 1
Tonnie Avatar answered Nov 11 '22 07:11

Tonnie