Я новичок в Android Studio и пытаюсь создать новую панель инструментов, но получаю "java.lang.ClassNotFoundException":
Ниже я нашел возможное решение, но не хочу понижать compileSdkVersion и targetSdkVersion с 28 до 27.
android.view.View $ OnUnhandledKeyEventListener
Я даже ничего не кодировал в "MainActivity.java". Я только что создал toolbar_layout.xml и не могу ничего просмотреть!
Как я могу исправить эту ошибку предварительного просмотра?
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
build.gradle (модуль: приложение)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.rob.toolbar"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
MainActivity.java
package com.example.rob.toolbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
layout="@layout/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
toolbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_dark">
</android.support.v7.widget.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.widget.RelativeLayout.measureChildHor horizontal (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)
на 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.measureChildHor horizontal (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)
at java.lang.Thread.run (Thread.java:745)