cren90
cren90

Reputation: 1427

Android Studio ClassCastException When Attempting to Open A Layout XML File

I have an Android Studio project composed of several modules as shown:

Project

myLibraryModule depends on both Facebook and ZXing and applicationModule depends on myLibraryModule.

I am able to open layout XML files in the ZXing library (Facebook doesn't contain any), but when I try to open a layout XML from either myLibrary or the application, I get a ClassCastException

ClassCastException: com.intellij.psi.impl.source.PsiPlainTextFileImpl cannot be cast to com.intellij.psi.xml.XmlFile: com.intellij.psi.impl.source.PsiPlainTextFileImpl cannot be cast to com.intellij.psi.xml.XmlFile

Additionally, when I try to create a layout file,

Layout Creation Dialog

I get a NullPointerException

Null Pointer Exception Dialog

however, the layout file is created. Attempting to open the file gives the ClassCastException.

I have tried creating the layout in other text editors (Notepad, Notepad++, etc) and have the same problem. I have re-installed Android Studio to no avail. I am running Beta 0.8.9 Build AI-135.1404660 and just checked for updates, none are available in the Beta Channel.

Uninstalled and reinstalled Android Studio, then recreated the projects manually. All of the layout files were good and all could be opened. I closed Android Studio at the end of the day and opened it the next day and everything was back to having the same issues.

Any thoughts?

Upvotes: 3

Views: 3001

Answers (1)

vidonism
vidonism

Reputation: 119

Not sure if you solved it or not by now. I had a similar issue using Android Studio 1.0.1 and 1.0.2.(got the same ClassCastException when opening any XML file, not only layouts). The issue in my case is cause due a XML file being too large (got a warning that the XML file exceeded a set limit of 2560000, mine was almost 9 MB). Removing it from the /res folder and a restart of Android Studio helped.

I hope the above info helps a bit.

Cheers,

Upvotes: 2

Related Questions