【问题标题】:ClassCast Exception Android StudioClassCastException Android Studio
【发布时间】:2015-12-12 11:22:40
【问题描述】:

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

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

谢谢。

【问题讨论】:

  • 你的密码是什么???
  • 发布代码对我来说不是问题。我不知道是什么引起的异常。所以我不知道要分享哪一部分代码。你能告诉我是什么原因造成的,或者我必须分享什么代码吗?
  • 您是第一次运行 Android Studio 吗?
  • 使用稳定版本。我认为这是 Android Studio 中的一个错误。
  • @David 然后看起来你有一个资源文件,你的 IDE 认为它是纯文本。确保它们都是有效的 XML。

标签: android xml android-studio intellij-idea classcastexception


【解决方案1】:

最后解决了这个问题。这个问题帮助了我。 Android Studio ClassCastException When Attempting to Open A Layout XML File 。我的值中有一个 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

【讨论】:

  • 如何在 mac os 上做到这一点?
  • 在应用程序中选择 android studio -> 右键单击​​ -> 显示内容。在那里你可以编辑 .properties 和 .vmoptions
【解决方案2】:

如果能分享一些代码sn-ps就更好了……

无论如何,就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>

但是在将组件连接到代码时:

ImageView img1 = (ImageView)context.findViewById(R.id.btn1);

这将触发 ClassCastException,因为您将 Button 强制转换为 ImageView 变量,您理解这是不可能的!

如果这不能解决您的问题,那么最好在确定哪个代码 sn-p 导致错误后发布一些代码 sn-ps!

【讨论】:

  • 。感谢您的回答。发布代码对我来说不是问题。我不知道是什么引起的异常。所以我不知道要分享哪一部分代码。你能告诉我是什么原因造成的,或者我必须分享什么代码吗?
  • 这是看到的异常。No line number nothing.ClassCastException: com.intellij.psi.impl.source.PsiPlainTextFileImpl 无法转换为 com.intellij.psi.xml.XmlFile。我找不到页面,你能吗?
猜你喜欢
  • 2017-03-04
  • 1970-01-01
  • 2014-12-12
  • 2015-07-09
  • 2014-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多