简体   繁体   中英

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. 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

Based on the ton of suggestions I've seen from related questions, I've tried the following:

  1. Invalidated cache and restarted Android Studio
  2. Rebuilt the project
  3. Synced project with gradle files
  4. Changed the definition of AppTheme in styles.xml from

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

to:

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

  1. Tried different API version in editor (23, 22)

I have also tried changing from AppTheme to AppCompat with no luck

None of these options worked.

I have a broken addon file in SDK manager, but am not sure this is the cause.

在此处输入图片说明

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.

Now download the newest Android SDK from: https://developer.android.com/studio/index.html

It's available in the bottom of page, in Get just the command line tools section. 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. It may prompt you to choose Adroid SDK path, if you didn't do the previous point correctly.

Hope it will help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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