【问题标题】:parseSdkContent failed Could not initialize class android.graphics.TypefaceparseSdkContent 失败无法初始化类 android.graphics.Typeface
【发布时间】:2014-07-08 15:55:05
【问题描述】:

当我打开布局编辑器时,eclipse 出现此错误:

parseSdkContent failed
Could not initialize class android.graphics.Typeface

当我尝试运行项目时,它给出了这个错误:

An internal error occurred during: "Launching myapp".
java.lang.NullPointerException

每次我收到此错误时,我都必须重新启动 Eclipse。有什么解决办法吗?今天突然出现这个问题。


XML 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#66000000"
     >

    <RelativeLayout
        android:id="@+id/refresh_match_layout"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:layout_centerInParent="true"
        android:layout_margin="15dp"
        android:background="@drawable/app_detay_lay_bg"
        android:orientation="vertical"
        android:padding="10dp"
        android:visibility="visible" >

        <ImageView
            android:id="@+id/app_icon"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:padding="10dp"
            android:textColor="#ffffff"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:textColor="#000000"
            android:layout_toRightOf="@+id/app_icon"
            android:layout_marginTop="2dp"
            android:textSize="20sp" />

        <ImageButton
            android:id="@+id/app_detail_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="2dp"
            android:background="@null"
            android:src="@drawable/settings_detail"/>

        <ImageButton
            android:id="@+id/app_remove_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/app_icon"
            android:layout_alignTop="@+id/app_detail_button"
            android:background="@null"
            android:src="@drawable/settings_remove" />

    </RelativeLayout>

</RelativeLayout>

错误图片:

【问题讨论】:

  • 这是发生在任何新项目上还是仅在这个项目上?
  • 您最近是否更新了 SDK 工具或 ADT 插件,如果有,请再次检查两者都没有更新
  • 这只发生在这个项目中,我没有更新任何东西。幸运的是,它现在已修复。

标签: android eclipse android-layout nullpointerexception


【解决方案1】:

我删除了home/.android文件夹,现在一切正常了。

Windows中你可以在C:/Users/User/找到这个文件夹

来源:https://stackoverflow.com/a/5883841/3681056

注意:当您在同一台计算机上(并使用相同的 .android 文件)有 2 个版本的 SDK 和 eclipse 时会发生这种情况,如果您在另一个版本上打开另一个版本会出现此错误。

【讨论】:

  • 别忘了重启eclipse :)
  • 如果您有一个使用地图的应用程序,则在删除 .android 文件夹时会损坏。地图窗口将只显示一个带有缩放图标的空白屏幕。
  • 不过要小心 - 您的 .android 文件夹包含您的 AVD、调试密钥库等。相反,您可能想将其移动到其他地方。
  • 在 Mac 上,可以在~/.android找到该文件夹​​
  • 只需删除 ~/.android/avd 而不是删除整个文件夹。它对我有用。您需要删除 AVD 的 .ini 文件。然后重启eclipse就可以解决你的问题了。
【解决方案2】:

删除“.android”暂时解决了我的问题,因为过了一段时间它又开始出现了..

这是另一个可能有帮助的原因和修复方法。发生这种情况是因为在同一台机器上存在 2 个版本的 SDK,但如果您只有一个版本(可能是 21),只需下载 API 的 SDK 平台20(4.4W),因为 21 的“layoutlib.jar”有问题)。开始应用以下内容:

  • 关闭 Eclipse

  • 导航到您的 sdk 文件夹(类似于 C:\adt-bundle-windows-x86_64-20140321\sdk)

  • 转到platforms文件夹 -> android-21 文件夹 -> data 文件夹并重命名 layoutlib.jar(仅用于备份)

  • 将相同的文件 (layoutlib.jar) 从您的 android-20 文件夹复制到此文件夹“android-21”

  • 启动 Eclipse

【讨论】:

  • 这解决了我的问题。
【解决方案3】:

删除 home/.android 没用,我删除 ~/.android/avd 它对我有用 :)

【讨论】:

    【解决方案4】:

    我也遇到了这个错误

    parseSdkContent 失败 无法初始化类 android.graphics.Typeface

    但我只能在 Windows 7 64 位操作系统上将我的 Eclipse ADT 从 64 位更改为 32 位后才能解决它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 2018-12-09
    • 2022-01-18
    • 2021-02-19
    • 1970-01-01
    • 2012-10-29
    相关资源
    最近更新 更多