Android studio 不渲染布局预览
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26594881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android studio not rendering layout preview
提问by Tupaschoal
I've been using Android Studio 0.8.6 to develop apps and am having problems with the layout preview when using API21. I get the following error:
我一直在使用 Android Studio 0.8.6 开发应用程序,并且在使用 API21 时遇到布局预览问题。我收到以下错误:
Rendering Problems: The following classes could not be instantiated: -?android.support.v7.widget.Toolbar
渲染问题:无法实例化以下类:-?android.support.v7.widget.Toolbar
I have SDK Build tools up-to-date (21.0.2) as well as the full API21 downloaded and installed. My targetSDKVersion is set to 21 on the gradle file. If I change the preview to render with API20, everything seems fine. Exception details are provided below.
我有最新的 SDK Build 工具 (21.0.2) 以及完整的 API21 下载和安装。我的 targetSDKVersion 在 gradle 文件中设置为 21。如果我将预览更改为使用 API20 渲染,一切似乎都很好。下面提供了例外的详细信息。
Thanks!
谢谢!
Exception Details java.lang.ClassNotFoundException: android.support.v4.content.ContextCompatApi21 ??at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148) ??at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ??at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ??at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:319) ??at android.support.v7.internal.widget.TintManager.getDrawable(TintManager.java:133) ??at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62) ??at android.support.v7.widget.Toolbar.(Toolbar.java:248) ??at android.support.v7.widget.Toolbar.(Toolbar.java:190) ??at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ??at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806) ??at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) ??at android.view.LayoutInflater.rInflate(LayoutInflater.java:782) ??at android.view.LayoutInflater.inflate(LayoutInflater.java:504) ??at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
异常详情 java.lang.ClassNotFoundException: android.support.v4.content.ContextCompatApi21 ??at com.intellij.util.lang.UrlClassLoader.findClass(UrlClassLoader.java:148) ??at java.lang.ClassLoader.loadClass(ClassLoader .java:424) ??at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ??at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:319) ??at android.support。 v7.internal.widget.TintManager.getDrawable(TintManager.java:133) ??at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62) ??at android.support.v7.widget。 Toolbar.(Toolbar.java:248) ??at android.support.v7.widget.Toolbar.(Toolbar.java:190) ??at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ??在 android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806) ?? 在 android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64) ??at android.view.LayoutInflater.rInflate(LayoutInflater.java:782) ??at android.view.LayoutInflater.inflate(LayoutInflater.java:504) ??at android .view.LayoutInflater.inflate(LayoutInflater.java:385)
采纳答案by ianhanniballake
The most recent version of Android Studio is 0.8.14and this fixes a number of issues with API21. Note that as per the Android Studio 0.8.12 announcement(under 'No patches'):
最新版本的 Android Studio 是0.8.14,这修复了API21的许多问题。请注意,根据Android Studio 0.8.12 公告(在“无补丁”下):
We've found and fixed several significant bugs in the patching mechanism. One of these bugs meant that upgrading to a new version, while resulting in a functionally identical installation, would also result in slightly different binary contents (for example, some timestamps inside .jar files would differ). This meant that the actual binary signatures would not match, which broke for example the application signature checks.
We have now found and fixed that bug, but because there are many different binary variations of a given previous version, we cannot create a single patch to update to the new version. Therefore, for this version we will require a full download of the IDE. From this version forward we should be able to accurately install updates while preserving the application signatures.
我们发现并修复了修补机制中的几个重要错误。这些错误之一意味着升级到新版本,同时导致功能相同的安装,也会导致二进制内容略有不同(例如,.jar 文件中的某些时间戳会有所不同)。这意味着实际的二进制签名将不匹配,这会破坏例如应用程序签名检查。
我们现在已经发现并修复了该错误,但是由于给定的先前版本有许多不同的二进制变体,我们无法创建单个补丁来更新到新版本。因此,对于此版本,我们需要完整下载 IDE。从这个版本开始,我们应该能够在保留应用程序签名的同时准确安装更新。
So you'll need to manually install the latest build.
所以你需要手动安装最新的 build。
回答by Sotti
This problem was back to me in Android Studio 1.2.
这个问题在 Android Studio 1.2 中又回到了我的身边。
This is what I did and worked.
这就是我所做的和工作的。
- Clean Project
- Rebuild project
- Sync Gradle
- Press update layout preview button
- 清洁工程
- 重建项目
- 同步摇篮
- 按更新布局预览按钮
回答by Sandeep Londhe
Try unselecting "Automatically pick Best"in the Preview pane and select an older API when you view your layout XML. This is located in the menu bar where you select the device and theme you want your preview to use, all the way on the right.
尝试在预览窗格中取消选择“自动选择最佳”,并在查看布局 XML 时选择较旧的 API。它位于菜单栏中,您可以在其中选择要预览使用的设备和主题,一直在右侧。
回答by s.g
Change your style parent to Theme.AppCompat.Light.NoActionBar
instead of Theme.AppCompat.Light.DarkActionBar
in styles.xml
......... it worked for me.
将您的样式父项更改为Theme.AppCompat.Light.NoActionBar
而不是Theme.AppCompat.Light.DarkActionBar
in styles.xml
.........它对我有用。
回答by iSab
This is a known issue, see below.
这是一个已知问题,见下文。
Spurious Render Exception
虚假渲染异常
The specific render error message is: The following classes could not be found:
具体的渲染错误信息是:找不到以下类:
android.support.v7.internal.app.WindowDecorActionBar
Despite the error message, the layout preview is correct and the message can be safely ignored. The issue has already been fixed in 2.0 preview. See bug 192102for more details. (Issue link is not valid anymore).
尽管有错误消息,但布局预览是正确的,可以安全地忽略该消息。该问题已在 2.0 预览版中修复。有关详细信息,请参阅错误 192102。(问题链接不再有效)。
回答by exequielc
I'm facing the same problem in android studio 2.2
我在 android studio 2.2 中面临同样的问题
This is what I did and nothing
这就是我所做的,什么也没有
-Clean Project
- 清洁项目
-Rebuild project
-重建项目
-Sync Gradle
-同步摇篮
The only thing that actually worked for me was Restarting android studio (close and reopen)
唯一对我有用的是重新启动android studio(关闭并重新打开)
回答by Lucas Fox
- Clean Project
- Rebuild project
- Sync Gradle
- Press update layout preview button
- 清洁工程
- 重建项目
- 同步摇篮
- 按更新布局预览按钮
The "Update layout preview" button is located above the android phone preview, it's the one with circular blue arrows, right by the magnifying glass zoom buttons.
“更新布局预览”按钮位于 android 手机预览上方,它是带有圆形蓝色箭头的按钮,就在放大镜缩放按钮旁边。
note: this solution appears to do nothing until the update layout button is pressed at the final step, and then it works. This fixed the problem for me. I am using Android Studio v2.1.2.
注意:在最后一步按下更新布局按钮之前,此解决方案似乎什么都不做,然后它就可以工作了。这为我解决了问题。我正在使用 Android Studio v2.1.2。
Cheers!
干杯!
回答by Isaías Carrera Ventura
- Clean Project
- Rebuild project
- Sync Gradle
- Press update layout preview button
- 清洁工程
- 重建项目
- 同步摇篮
- 按更新布局预览按钮
Or
或者
in your XML file press right click and mark as XML.
在您的 XML 文件中按右键并标记为 XML。
that should work.
那应该工作。