2014-10-27 106 views
20

我一直在使用Android Studio 0.8.6開發應用程序,並且在使用API​​21時遇到佈局預覽問題。我收到以下錯誤:Android studio沒有渲染布局預覽

Rendering Problems: The following classes could not be instantiated: - android.support.v7.widget.Toolbar

我有SDK構建工具最新(21.0.2)以及完整的API21下載和安裝。我的targetSDKVersion在gradle文件中設置爲21。 如果我更改預覽以使用API​​20呈現,一切似乎都很好。異常詳情如下。

謝謝!

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)

回答

6

Android Studio的最新版本是0.8.14,這解決了API21的一些問題。注意,每Android Studio 0.8.12 announcement(下「沒有補丁」):

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.

所以你需要手動安裝latest build

+0

這實際上解決了它,非常感謝:) – Tupaschoal 2014-10-27 19:40:28

+0

我在0.8.12版本沒有補丁更新(從頭開始),現在我在0.8.14(2升級執行)。嘗試在我的應用中使用新的工具欄小部件時,我仍然看到上述例外。我是否必須從零開始安裝0.8.14版本?如果是,那麼0.8.12升級最後一個需要無補丁安裝的版本? – 2014-12-02 15:45:42

+0

沒關係......用gradle(再次)與resyncing不知何故使錯誤消失 – 2014-12-02 16:53:34

7

嘗試取消選擇在「預覽」窗格中選擇「自動選擇最佳」,然後在查看佈局XML時選擇較舊的API。它位於菜單欄中,您可以從右側選擇要預覽的設備和主題。

+0

正如我所述,這部分解決了它。我可以選擇API20並正確呈現它,但不會仍然可以使用API​​21,這是我的目標:( – Tupaschoal 2014-10-27 19:39:49

+0

你有更新eclipse adt插件嗎? – AndroidHacker 2014-10-28 06:20:42

+1

我做了,實際上爲我解決的是上面的答案,更新Android Studio :) 感謝您的幫助! – Tupaschoal 2014-10-28 13:23:03

43

在Android Studio 1.2中,我遇到了這個問題。

這就是我所做的和工作的。

  1. 清理項目
  2. 重建項目
  3. 同步搖籃
  4. 新聞更新佈局預覽按鈕
+0

這適用於Android Studio 1.2。謝謝! – user3557327 2015-05-07 14:23:44

+0

我在創建工具欄時遇到了同樣的問題。我遵循你的指示。應用您提到的所有步驟。並完美地工作! 謝謝! – 2015-05-28 09:21:53

+0

這些步驟不會解決AS 1.2.2中的issie – 2015-06-24 04:43:39

3

這是一個known issue,見下文。

Spurious Render Exception

具體呈現錯誤消息是: 以下類找不到:

android.support.v7.internal.app.WindowDecorActionBar 

儘管錯誤消息,佈局預覽是正確的,消息可以安全地忽略。該問題已在2.0預覽中得到修復。 有關更多詳細信息,請參閱 bug 192102 。 (問題鏈接不再有效)。

0

我在android studio 2中遇到同樣的問題。2

這是我做的,沒有什麼

- 衛生項目

-rebuild項目

-Sync搖籃

的唯一實際工作對我來說是重新啓動機器人工作室的事情(關閉並重新打開)

+0

重新啓動也適用於我。 – 2017-11-03 17:48:28

0
  1. 清潔項目
  2. 重建項目
  3. 同步搖籃
  4. 新聞更新佈局預覽按鈕

「更新佈局預覽」按鈕位於上方的android手機預覽,它是一個圓形的藍色箭頭,右靠放大玻璃變焦按鈕。

注意:此解決方案似乎什麼都不做,直到在最後一步按下更新佈局按鈕,然後它才起作用。這爲我解決了這個問題。我正在使用Android Studio v2.1.2。

乾杯!

3

改變你的風格父母Theme.AppCompat.Light.NoActionBar而不是Theme.AppCompat.Light.DarkActionBarstyles.xml .........它爲我工作。

0
  • 清理項目
  • 重建項目
  • 同步搖籃
  • 新聞更新佈局預覽 按鈕
在XML文件中按右鍵點擊,標記爲XML

或者

應該工作。

+0

此問題已被解答。如果您希望爲其他人記錄此信息,請發佈[自我回答問題](https://stackoverflow.blog/2011/07/its-ok-to-ask-and-answer-your-own-questions/) – akash93 2017-01-03 02:12:58