3

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

Project

  • facebookLibraryModule
  • zxingLibraryModule
  • myLibraryModule
  • applicationModule

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?

cren90
  • 1,367
  • 2
  • 17
  • 30
  • Are you sure you are adding a .xml extension to your layout file name? – Michael Krause Oct 16 '14 at 22:33
  • Yes, I have tried it by typing in just the base name, and with the xml extension. If no extension is supplied, .xml is used anyway. – cren90 Oct 16 '14 at 22:40
  • 1
    Did you tried android studio stable release version? – Akhil Oct 17 '14 at 02:05
  • Today after I opened my studio I faced the same problem for the first time. Did you manage to solve it? – Hadi Nov 24 '14 at 13:44
  • Sorry for the delay, priority shift led to temporarily derailing the Android Studio effort. @Akhil I am currently using the official 1.0.1 build and am still experiencing the problem. – cren90 Dec 19 '14 at 01:12
  • @Hadi, unfortunately I have not found a solution. – cren90 Dec 19 '14 at 01:13
  • @cren. Hi, i have caught up with this same exception. Have you found a solution? – David Dec 14 '15 at 12:22

1 Answers1

2

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,

vidonism
  • 119
  • 1
  • 5
  • I do have a couple of 5MB value files... I will give it a shot. – cren90 Jan 06 '15 at 22:59
  • Try to remove them from the project and restart Android studio. Without restart it won't work. – vidonism Jan 07 '15 at 12:14
  • @vidonism. My total layout folder size is 2.95MB. I am getting the same error. I deleted the layouts and yet the same result. Please help. – David Dec 14 '15 at 12:24
  • @vidonism . Thanks. I did not notice a 11 MB xml file in values folder. Deleted that and the problem was fixed. But that 11 MB file is necessary for my project. How can i overcome that. – David Dec 14 '15 at 12:47
  • @David If possible try to split it in several XML files (chunks). If the file contains image data as base64 text (which was my case) then put the images in the project as such and just 'link' to them in the XML file – vidonism Jan 07 '16 at 11:40