My layout does not render

Asked

Viewed 1,183 times

4

I was watching and copying a code from the first class of Material Design of the Thiengo Calopsita youtube, It turns out that the file xml of activity_main and of toolbar_bottom is not rendering in Android Studio, according to the error, there is some problem in the class android.support.v7.widget.Toolbar!

How to render layout?

follows the code activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/tb_main"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary" />

    <TextView
        android:layout_below="@+id/tb_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="@string/hello_world"
        android:textColor="@color/black"/>

    <include
        android:id="@+id/inc_tb_bottom"
        layout="@layout/toolbar_Bottom"/>

</RelativeLayout>

Follows the code of toolbar_bottom.xml

<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/tb_bottom"
    android:layout_alignParentBottom="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/Theme.MyThemeBottom">

    <ImageView
        android:id="@+id/iv_settings"
        android:src="@drawable/settings"
        android:layout_width="24dp"
        android:layout_height="24dp"
        />

</android.support.v7.widget.Toolbar>

Follow the generated error:

java.lang.NoSuchFieldError: View_theme
    at android.support.v7.internal.widget.ViewUtils.themifyContext(ViewUtils.java:124)
    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:198)
    at android.support.v7.widget.Toolbar.<init>(Toolbar.java:192)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:379)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:99)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:688)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:677)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
  • 1

    Go on Build > Clean Project in your Android Studio

2 answers

0

  1. Try switching <android.support.v7.widget.Toolbar for < Toolbar
  2. And trade app:theme="@style/Theme.MyThemeBottom"> for android:theme="@style/Theme.MyThemeBottom">

Made that of a Clean Build.

0

Next: In the Preview Window at the top there is a line with several icons, the last icon is the android doll with the title : "Android Version to use when Rendering layouts..." switch from 22 to 21 that resolves

Browser other questions tagged

You are not signed in. Login or sign up in order to post.