25

I tried fixing this for ages now, but I don't know what to do. How do I get it to display a preview? Here is a screenshot of the code:

img

slavoo
  • 5,798
  • 64
  • 37
  • 39
Mattias
  • 251
  • 1
  • 3
  • 3

8 Answers8

25

Solved :

Try 1 : Just close and open the Android Studio

Try 2 : Build -> Clean project -> rebuild

Try 3 : Build -> Clean project -> rebuild -> restart Android studio

Mi

ravz
  • 968
  • 10
  • 21
14

From Menu Open file option and choose option Close Project.

then restart your project android.

this will resolve your issue.

mehmoodnisar125
  • 1,469
  • 18
  • 14
5

in my case, clean and build didn't work, I just close the project and open it again, it's solved

4

The attached screenshot shows your Project is not sync properly. Here are some of the possible steps:

  1. Use Sync Project with Gradle Files for more Here is answer with more detail.
  2. If you made huge changes to project or changed package names etc. use rebuild
    In menu Build => Rebuild Project.
  3. Preview may not show if an API is selected that is not properly installed. Check Answer here.

One of the above should fix the problem. If none of the above work try restarting IDE (Android Studio).

Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69
4

Follow these steps-

  1. If you have any incomplete statement(s) in your code (probably where you left it last time) then comment those lines to make them inactive.
  2. Go to Build=>Rebuild to rebuild the project.
  3. Uncomment those lines to make them active again and you are done!!
hafiz031
  • 2,236
  • 3
  • 26
  • 48
3

Close the android studio and reopen the project again. If not work replace all 'compile' with 'implementation' from build.gradle file. Because it is obsolete now and will be removed at the end of 2018. I solved this kind of problem like that.

Istiyak
  • 693
  • 6
  • 15
2

I tried above answers. But, sometimes they work and sometimes not.

I tried -

File -> Invalidate Caches/ Restart -> Invalidate and restart

And it always works for me.

R4444
  • 2,016
  • 2
  • 19
  • 30
0

I do this to solved the problem:

  1. type Ctrl + Shift + A to open the "Actions" search window

  2. input "Sync Project with Gradle Files" , then type Enter

  3. wait for Sync finished

djzhao
  • 934
  • 10
  • 9