Layout Edtior未显示工具栏 - NegativeArraySizeException

时间:2018-01-05 18:36:19

标签: android android-studio-3.0 graphical-layout-editor

所有功能在手机和模拟器上运行良好,但我无法在Android Studio中使用布局编辑器,因为我收到以下错误:

无法实例化以下类:

  • android support.v7.widget.Toolbar(Open Class,Show Exception,Clear Cache)

我在另一个布局中使用ConstraintLayout也一样。

例外详细信息:

java.lang.NegativeArraySizeException
    at android.support.v7.appcompat.R$styleable.<clinit>(Unknown Source)
    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:235)
    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:228)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:264)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:222)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:211)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:337)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:348)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:248)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
    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)

图片看起来如何:
enter image description here

我的工具栏布局XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="?attr/toolbarTheme"
    app:popupTheme="?attr/toolbarPopupTheme"/>

Gradle for&#34;支持库&#34;:

// Support Library  
implementation "com.android.support:support-core-utils:${supportLibVersion}"
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:gridlayout-v7:${supportLibVersion}"
implementation "com.android.support:cardview-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

supportLibVersion =&#39; 27.0.2&#39;

我使用Android Studio版本 3.0.1

我已经在其他StackOverflow线程中完成了什么:
- 无效的缓存和重新启动
- 清洁项目和重建项目
- 我使用的主题从父母改变了#34; Theme.AppCompat&#34; to&#34; Base.Theme.AppCompat&#34;

1 个答案:

答案 0 :(得分:0)

<强>问题:
如果您在 attr.xml 中定义的一个<declare-stylable>标记中包含到很多属性,布局编辑器似乎会遇到一些麻烦!

<强>解决方案:
我在一个<declare-stylable>代码中有 49 属性 如果我删除 5 属性,那么我 45 ,布局编辑器正在运行。

我还在Google Issue Tracker上添加了一个问题:
https://issuetracker.google.com/issues/71641021

Google问题更新
这已针对Android Studio 3.1版本进行了修复。