类播异常Android Studio

类播异常Android Studio,android,xml,android-studio,intellij-idea,classcastexception,Android,Xml,Android Studio,Intellij Idea,Classcastexception,在运行我的项目时,我在android studio中获得了ClassCastException。谁能告诉我是什么导致了这个错误 ClassCastException:com.intellij.psi.impl.source.PsiPlainTextFileImpl无法强制转换为com.intellij.psi.xml.XmlFile 谢谢。如果您能分享一些代码片段,那就更好了 无论如何,就ClassCastException而言,这意味着您正在声明某种类型的变量,并将其分配给布局xml文件中定义

在运行我的项目时,我在android studio中获得了ClassCastException。谁能告诉我是什么导致了这个错误

ClassCastException:com.intellij.psi.impl.source.PsiPlainTextFileImpl无法强制转换为com.intellij.psi.xml.XmlFile


谢谢。

如果您能分享一些代码片段,那就更好了

无论如何,就
ClassCastException
而言,这意味着您正在声明某种类型的变量,并将其分配给布局xml文件中定义的另一种类型

例如,在xml中,您可能有:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:layout_width="wrap_content">
</Button>
</LinearLayout>
这将触发一个
ClassCastException
,因为您正在对ImageView变量强制转换一个按钮,这是您所理解的不可能的


如果这不能解决您的问题,那么最好在找出导致错误的代码段之后发布一些代码段

终于解决了这个问题。这个问题帮助了我。我的值中有一个11MB的xml文件。这就是问题所在。删除后,问题就解决了

如果您想使用大型XML文件,请在Android Studio的bin文件夹中的idea.properties和vmoptions中添加以下代码

**Add in idea.properties**
 #-------------------------------------------------------------    --------
# Maximum file size (kilobytes) IDE     should provide code assistance for.
# The larger file is the slower its.    editor works and higher overall system     memory requirements are
# if code assistance is enabled.     Remove this property or set to very.    large number if you need
# code assistance for any files     available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=999999


**Add in vmoptions**


-Didea.max.intellisense.filesize=999999     # <--- new line

Reference: https://stackoverflow.com/questions/23057988/file-size-exceeds-configured-limit-2560000-code-insightfeatures-not-availabl
**加载项idea.properties**
#-------------------------------------------------------------    --------
#最大文件大小(KB)IDE应为提供代码帮助。
#文件越大,速度越慢。编辑器工作和更高的总体系统内存要求
#如果启用了代码帮助。删除此属性或将其设置为“非常”。如果需要,请选择大号码
#任何可用文件的代码帮助,无论其大小。
#---------------------------------------------------------------------
idea.max.intellisense.filesize=999999
**附加模块选项**

-Didea.max.intellisense.filesize=999999#你的代码是什么???发布代码对我来说不是问题。我不知道是什么原因导致了异常。所以我不知道该共享代码的哪一部分。你能告诉我是什么原因造成的,或者我必须分享什么代码吗?你是第一次运行Android Studio吗?使用稳定的版本。我认为这是Android Studio中的一个bug。@David然后,似乎您有一个IDE认为是纯文本的资源文件。确保它们都是有效的XML..谢谢你的回答。发布代码对我来说不是问题。我不知道是什么原因导致了异常。所以我不知道该共享代码的哪一部分。你能告诉我是什么导致了这一点,或者我必须共享什么代码吗?这是所看到的异常。没有行号nothing.ClassCastException:com.intellij.psi.impl.source.PsiPlainTextFileImpl不能转换为com.intellij.psi.xml.XmlFile。我找不到该页面,可以吗?如何在mac os上执行此操作?在应用程序中选择android studio->右键单击->显示内容。您可以在那里编辑.properties和.vmoptions
**Add in idea.properties**
 #-------------------------------------------------------------    --------
# Maximum file size (kilobytes) IDE     should provide code assistance for.
# The larger file is the slower its.    editor works and higher overall system     memory requirements are
# if code assistance is enabled.     Remove this property or set to very.    large number if you need
# code assistance for any files     available regardless their size.
#---------------------------------------------------------------------
idea.max.intellisense.filesize=999999


**Add in vmoptions**


-Didea.max.intellisense.filesize=999999     # <--- new line

Reference: https://stackoverflow.com/questions/23057988/file-size-exceeds-configured-limit-2560000-code-insightfeatures-not-availabl