【问题标题】:Rendering problems in xml preview in Android Studio with API 24使用 API 24 在 Android Studio 中的 xml 预览中呈现问题
【发布时间】:2017-02-24 12:31:52
【问题描述】:

我最近将 Android Studio 更新到 2.2.1 版,将构建工具更新到 24.0.3 并将 API 级别更新到 24,但是当我创建一个新项目(或打开现有项目)时,我的布局无法在预览模式下呈现。 我收到此错误日志:

java.lang.NullPointerException
at android.graphics.Paint_Delegate.nGetFontMetricsInt(Paint_Delegate.java:607)
at android.graphics.Paint.nGetFontMetricsInt(Paint.java)
at android.graphics.Paint.getFontMetricsInt(Paint.java:1668)
at android.text.TextLine.expandMetricsFromPaint(TextLine.java:661)
at android.text.TextLine.handleRun(TextLine.java:860)
at android.text.TextLine.measureRun(TextLine.java:387)
at android.text.TextLine.measure(TextLine.java:277)
at android.text.TextLine.metrics(TextLine.java:251)
at android.text.BoringLayout.isBoring(BoringLayout.java:310)
at android.widget.TextView.onMeasure(TextView.java:7069)
at android.view.View.measure(View.java:19731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:642)
at android.view.View.measure(View.java:19731)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19731)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:545)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:342)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:966)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$53(RenderTask.java:659)
at com.android.tools.idea.rendering.RenderTask$$Lambda$139/905690897.call(Unknown Source)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

以及刷新选项,但失败了

样式定义如下:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

我选择的主题是AppTheme

根据我从相关问题中看到的大量建议,我尝试了以下方法:

  1. 缓存无效并重新启动 Android Studio
  2. 重建项目
  3. 使用 gradle 文件同步项目
  4. 更改了styles.xml中AppTheme的定义

style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"

到:

样式名称="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar"

  1. 在编辑器中尝试了不同的 API 版本 (23, 22)

我也尝试过从AppTheme 更改为AppCompat,但没有成功

这些选项都不起作用。

我在 SDK 管理器中有一个损坏的插件文件,但不确定是不是这个原因。

我愿意提供任何其他可能对我有帮助的信息。

【问题讨论】:

  • 移除损坏的包并重新安装
  • 我无法删除,我在SDK Manager中尝试删除,整个过程仍然存在
  • 唯一的“解决方案”是卸载Android Studio,删除所有相关目录,删除SDK文件夹并从头重新安装。现在可以正常工作了

标签: android xml android-layout android-studio


【解决方案1】:

转到您的 android-sdk 路径(您会看到它选择了File -&gt; Project Structure),如果打开删除此文件夹,请关闭 Android Studio 和 Android SDK 管理器。

现在从https://developer.android.com/studio/index.html下载最新的Android SDK

它位于页面底部的Get just the command line tools 部分。将其解压/安装在您已删除现有文件的位置。确保文件夹名称与已删除相同,如果不重命名。

毕竟,打开 Android Studio。如果您没有正确执行上一点,它可能会提示您选择 Adroid SDK 路径。

希望对你有帮助

【讨论】:

  • 我在我的电脑上卸载/删除了与 Android 相关的所有内容,然后重新开始,这就是我能够克服这个问题的方法:|
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-05
  • 1970-01-01
  • 2015-10-19
  • 1970-01-01
  • 2017-01-29
相关资源
最近更新 更多