简体   繁体   English

使用API​​ 24的Android Studio中的XML预览中的渲染问题

[英]Rendering problems in xml preview in Android Studio with API 24

I recently updated Android Studio to version 2.2.1, Build Tool to 24.0.3 and API Level to 24, but when I create a new project (or open an existing one) my layout does not render in preview mode. 我最近将Android Studio更新为版本2.2.1,将构建工具更新为24.0.3,将API级别更新为24,但是当我创建一个新项目(或打开一个现有项目)时,我的布局无法在预览模式下呈现。 I get this error log: 我收到此错误日志:

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)

and the option to refresh, which fails 和刷新选项,失败

在此处输入图片说明

The styles is defined like this: 样式定义如下:

<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"/>

The theme I've selected is AppTheme 我选择的主题是AppTheme

Based on the ton of suggestions I've seen from related questions, I've tried the following: 根据我从相关问题中看到的大量建议,我尝试了以下方法:

  1. Invalidated cache and restarted Android Studio 无效的缓存并重新启动了Android Studio
  2. Rebuilt the project 重建项目
  3. Synced project with gradle files 与gradle文件同步的项目
  4. Changed the definition of AppTheme in styles.xml from 更改了styles.xml中AppTheme的定义

style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" 样式名称=“ AppTheme” parent =“ Theme.AppCompat.Light.DarkActionBar”

to: 至:

style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar" 样式名称=“ AppTheme” parent =“ Base.Theme.AppCompat.Light.DarkActionBar”

  1. Tried different API version in editor (23, 22) 在编辑器中尝试过不同的API版本(23,22)

I have also tried changing from AppTheme to AppCompat with no luck 我也尝试AppTheme更改为AppCompat ,但没有运气

None of these options worked. 这些选项均无效。

I have a broken addon file in SDK manager, but am not sure this is the cause. 我在SDK管理器中的加载项文件损坏,但是不确定这是原因。

在此处输入图片说明

Am willing to provide any other information that might aid in helping me. 愿意提供任何其他可以帮助我的信息。

Go to your android-sdk path (you would see it choosing File -> Project Structure ), close Android Studio and Android SDK Manager if open an delete this folder. 转到您的android-sdk路径(选择File -> Project Structure会看到它),如果打开Delete this folder,则关闭Android Studio和Android SDK Manager。

Now download the newest Android SDK from: https://developer.android.com/studio/index.html 现在从以下网址下载最新的Android SDK: https//developer.android.com/studio/index.html

It's available in the bottom of page, in Get just the command line tools section. 它在页面底部的Get just the command line tools部分中可用。 Unpack/install it where you've already deleted the existing ones. 将其解压缩/安装在已删除现有文件的地方。 Be sure that folder name is the same as deleted, if not rename it. 如果没有重命名文件夹,请确保该文件夹的名称与已删除的相同。

After all, open Android Studio. 毕竟,打开Android Studio。 It may prompt you to choose Adroid SDK path, if you didn't do the previous point correctly. 如果您没有正确执行上一点,它可能会提示您选择Adroid SDK路径。

Hope it will help 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM