创建工具栏时出现异常

时间:2018-07-17 12:32:37

标签: java android

当我要创建toolbar的版式时,
然后显示此异常:

  

java.lang.ClassNotFoundException:android.view.View $ OnUnhandledKeyEventListener           在org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:180)           在com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61)           在org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:118)           在java.lang.ClassLoader.loadClass(ClassLoader.java:424)           在java.lang.ClassLoader.loadClass(ClassLoader.java:357)           在org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:213)           在android.support.v7.widget.ViewUtils.isLayoutRtl(ViewUtils.java:58)           在android.support.v7.widget.Toolbar.onMeasure_Original(Toolbar.java:1578)           在android.support.v7.widget.Toolbar.onMeasure(Toolbar.java)           在android.view.View.measure_Original(View.java:22071)           在android.view.View_Delegate.measure(View_Delegate.java:80)           在android.view.View.measure(View.java:22035)           在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)           在android.widget.FrameLayout.onMeasure(FrameLayout.java:185)           在android.view.View.measure_Original(View.java:22071)           在android.view.View_Delegate.measure(View_Delegate.java:80)           在android.view.View.measure(View.java:22035)           在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:715)           在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)           在android.view.View.measure_Original(View.java:22071)           在android.view.View_Delegate.measure(View_Delegate.java:80)           在android.view.View.measure(View.java:22035)           在com.android.layoutlib.bridge.impl.RenderSessionImpl.measureView(RenderSessionImpl.java:590)           在com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:343)           在com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)           在com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)           在com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:544)           在com.android.tools.idea.rendering.RenderTask.lambda $ inflate $ 3(RenderTask.java:678)           在java.util.concurrent.FutureTask.run(FutureTask.java:266)           在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)           在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)           在java.lang.Thread.run(Thread.java:745)

我正在使用Android API 28和Android Studio 3.1版

我的布局代码是:

<?xml version="1.0" encoding="utf-8"?> 
 <android.support.v7.widget.Toolbar 
   xmlns:android="schemas.android.com/apk/res/android"    
   android:layout_width="match_parent" 
   android:layout_height="wrap_content" 
   android:background="@color/colorPrimary" 
   android:id="@+id/main_app_bar" 
   android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >     
 </android.support.v7.widget.Toolbar>

2 个答案:

答案 0 :(得分:0)

     xmlns:android="schemas.android.com/apk/res/android";   
remove semicolom(;) and try again

答案 1 :(得分:0)

use this :


<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:id="@+id/main_app_bar"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    xmlns:android="http://schemas.android.com/apk/res/android">
    </android.support.v7.widget.Toolbar>