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

36

当我打开布局编辑器时,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>

错误图片: 在此输入图像描述


这种情况是发生在所有新项目上还是只是这个项目? - Max McKinney
你最近更新了SDK工具或ADT插件吗?如果是的话,请再次检查两者是否有更新。 - Boardy
这只发生在这个项目中,我什么都没有更新。幸运的是,现在它已经修复了。 - Lazy
4个回答

88

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

Windows 中,您可以在 C:/Users/User/ 下找到此文件夹。

来源:https://dev59.com/12445IYBdhLWcg3wIG19#5883841

注意:当您的计算机上有两个版本的SDK和eclipse时(并且使用相同的 .android 文件),如果您打开其中一个版本,则另一个版本将出现此错误。


别忘了重新启动Eclipse :) - Safvan 7
如果您的应用程序使用地图,那么删除.android文件夹将会导致其崩溃。地图窗口将只显示一个空白屏幕和缩放图标。 - user2260040
8
注意,你的 .android 文件夹包含了你的 AVD、debug keystore 等等内容。你可能会想把它移到其他地方。 - Tad
1
在 Mac 上,该文件夹可以在 ~/.android 找到。 - Mike Ortiz
只需删除~/.android/avd文件夹而不是完整删除,这对我有效。您需要删除AVD的.ini文件。然后重新启动Eclipse即可解决问题。 - chaitanya

4

删除“.android”可以暂时解决我的问题,但过一段时间它又会出现。

这里是另一个可能有用的原因和解决方法...这是由于同一台机器上存在2个版本的SDK,但如果您只有一个版本(可能是21),只需下载API 20(4.4W)的SDK平台,因为21的“layoutlib.jar”存在问题。开始应用以下步骤:

  • 关闭Eclipse

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

  • 进入platforms文件夹 -> android-21文件夹 -> data文件夹并重命名layoutlib.jar(仅作备份)

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

  • 启动Eclipse


这解决了我的问题。 - F0r3v3r-A-N00b

2
删除 home/.android 是无用的,我删除了 ~/.android/avd 后它对我有效 :)

1

我也遇到了这个错误

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

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


我猜这与5.0 SDK有关 http://stackoverflow.com/questions/26829679/parsesdkcontent-failed-could-not-initialize-class-android-graphics-typeface-in - Paul Verest

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接