0

Every time i click on a java class file on the project panel, the file opens with some messed up code.

I have a backup for this project from 1 month ago so here is a example.

Old Comment.java code:

package tourisimo.com.licenta.dim.tourisimo_romania.DataType;

public class Comment {
    private String id;
    private String objectiveId;
    private String userId;
    private String parentId;
    private String date;
    private String text;
    private int likes;
    private int dislikes;

    public Comment(String id, String objectiveId, String userId, String date, String parentId, String text, int likes, int dislikes) {
        this.id = id;
        this.objectiveId = objectiveId;
        this.userId = userId;
        this.date = date;
        this.parentId = parentId;
        this.text = text;
        this.likes = likes;
        this.dislikes = dislikes;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDate() {
        return date;
    }
...

And now if i open the Comment.java file, the output is:

<component name="libraryTable">
  <library name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.0.0@aar">
    <CLASSES>
      <root url="jar://$USER_HOME$/.gradle/caches/transforms-2/files-2.1/7c34e5f4db0aa9910384a22c687e7922/jars/classes.jar!/" />
      <root url="file://$USER_HOME$/.gradle/caches/transforms-2/files-2.1/7c34e5f4db0aa9910384a22c687e7922/res" />
    </CLASSES>
    <JAVADOC />
    <SOURCES>
      <root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-viewmodel/2.0.0/41b56105d14b1151a963444875cab191271f43db/lifecycle-viewmodel-2.0.0-sources.jar!/" />
    </SOURCES>
  </library>
</component>

Also the file is displayed different in project window https://i.stack.imgur.com/qj4q6.jpg

Please help me!

Thank you.

1 Answers1

2

This is a bug with Android Studio. If you open your Comment.java on other text editors such as Notepad, you'd see that your file is still fine. This issue has also been asked here at SO, see this. The solution that worked for me can be found here, which is basically deleting the caches folder located in this directory(just use your username and your Android Studio version):

C:\Users\<your_user_name>\.AndroidStudio<version>\system\caches
Alvin Dizon
  • 1,855
  • 14
  • 34