简体   繁体   中英

Android studio not rendering layout preview

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:

Rendering Problems: The following classes could not be instantiated: - 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.

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.in flate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:385)

This problem was back to me in Android Studio 1.2.

This is what I did and worked.

  1. Clean Project
  2. Rebuild project
  3. Sync Gradle
  4. Press update layout preview button

The most recent version of Android Studio is 0.8.14 and this fixes a number of issues with API21. Note that as per the Android Studio 0.8.12 announcement (under 'No patches'):

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.

So you'll need to manually install the latest build .

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.

将样式父级更改为Theme.AppCompat.Light.NoActionBar而不是styles.xmlTheme.AppCompat.Light.DarkActionBar .........它对我Theme.AppCompat.Light.DarkActionBar

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 192102 for more details . (Issue link is not valid anymore).

I'm facing the same problem in 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)

  1. Clean Project
  2. Rebuild project
  3. Sync Gradle
  4. 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.

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.

Cheers!

  • Clean Project
  • Rebuild project
  • Sync Gradle
  • Press update layout preview button

Or

in your XML file press right click and mark as XML.

that should work.

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