user6694876
user6694876

Reputation:

Why does Android Studio show errors in my code but app still runs

I have recently upgraded my laptop and re-installed Android Studio to the latest version and imported my app. The problem I am facing now is that when Android Studio start it finishes the gradle build etc, but shows errors all over my code. I can still debug the app on my phone and all is working.

How can I get this resolved?

Thanks

Upvotes: 7

Views: 5524

Answers (3)

LBIRD S.E.
LBIRD S.E.

Reputation: 51

In my case (Windows), I have faced the same issue with 2 version of Android Studio,

1. Android Studio Arctic Fox | 2020.3.1 Patch 4 (My previous/normal IDE used)

2. Android Studio Dolphin | 2021.3.1 Patch 1 (My updated/current IDE used)

First, I thought this problem can be solve by Build>Clean Project, or Build>Rebuild Project, or File>Invalidate Caches..., but sadly won't work. So, I decided to update my IDE Arctic Fox to Dolphin.

Download from official site, installed with different folder (C:\Program Files\Android\Android Studio1), but project folder still same. During opening project, it won't run unless change Java version to Java 11 (File>Settings>Build, Exectuion, Deployment>Build Tools>Gradle>Gradle JDK>11 version).

Try opening several projects, however the IDE sometime still show the redline code, but the app can still debug/run as usual. Latest method I used, File>Invalidate Caches... And IDE haven't show any redline code.

*Remark: Don't know how long the latest method I used will work.

Upvotes: 0

Shubham Bahl
Shubham Bahl

Reputation: 11

If Methods named (A) (B) (C) (D), do not help you, then the following 4 steps are AGNI ASTRA.

Step 1 : Go To App Folder In Android Studio.

Step 2 : Locate Build Folder.

Step 3 : Delete Build Folder.

Step 4 : Sync File.

I will advise to use AGNI ASTRA, after trying, Methods named (A) (B) (C) (D) .

The Methods Are :

Method (A)

  • CLICK ON FILE IN ANDROID STUDIO
  • CLICK ON SYNC PROJECT WITH GRADLE FILES

Method (B)

  • CLICK ON FILE IN ANDROID STUDIO
  • CLICK ON INVALIDATE CACHES

Method (C)

  • CLICK ON BUILD IN ANDROID STUDIO
  • CLICK ON CLEAN PROJECT

Method (D)

  • CLICK ON BUILD IN ANDROID STUDIO
  • CLICK ON REBUILD PROJECT

Upvotes: 0

Casper
Casper

Reputation: 511

I finally resolved this when it happened to me. The steps I did to resolve my problem

  • Build -> clean
  • File -> invalidate caches / restart
  • Delete .idea folder, close and reopen project

Normally one of the first two first steps is enough but today I actually had to delete the entire .idea folder and reopen the project to get rid of the "errors" (only IDE errors, project still ran for me).

Upvotes: 6

Related Questions