问题
I am getting a ClassCastException in android studio while running my project. Can anyone tell me what is causing this error.
ClassCastException: com.intellij.psi.impl.source.PsiPlainTextFileImpl cannot be cast to com.intellij.psi.xml.XmlFile
Thanks.
回答1:
Sovled this atlast. This Question helped me. Android Studio ClassCastException When Attempting to Open A Layout XML File . I had a 11MB xml file in values. That was the problem. After deleting that, the problem was solved.
And if you want to use a large XML file add the below code in idea.properties and vmoptions in the bin folder of Android Studio.
**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
回答2:
It would be better if you can share some code snippets...
Anyways, as far as ClassCastException
is concerned, it means you are declaring a variable of some type and assigning it to another type you have defined in a layout xml file...
for example, in the xml you may have had:
<?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>
but while connecting the component to code:
ImageView img1 = (ImageView)context.findViewById(R.id.btn1);
This will fire a ClassCastException
because you are casting a Button to an ImageView variable which is as you understand not possible!
If this doesn't solve your problem then it would be better if you post some code snippets after figuring out which code snippet causes the error!
来源:https://stackoverflow.com/questions/34239231/classcast-exception-android-studio