android - Android - 无法实例化一个或多个类
问题描述
我目前正在开发 Android UI,并遇到以下问题。
根据android.support.design.widget.AppBarLayout
注释,我假设这是 Gradle 的问题。我也无法解决以下问题。
下面是gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "shapetheworld.application.shapetheworld"
minSdkVersion 18
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'
}
}
}
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
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'
}
下面是activity_main.xml
文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="shapetheworld.application.shapetheworld.MainActivity"
tools:layout_editor_absoluteY="25dp">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.constraint.ConstraintLayout>
注意:如果有关系,我使用的是 Android Studio 3.1.4
此外,一些参考资料表明问题可能出在style.xml
下面的文件中。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
参考:
解决方案
您需要为您使用的所有支持库提供相同的版本。现在,您可以替换此行
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
和
implementation 'com.android.support:appcompat-v7:27.1.0'
还将您的compileSdkVersion
andtargetSdkVersion
版本更改为 27。
推荐阅读
- javascript - 如何处理 MEAN 应用程序中的数据库更改
- elasticsearch - Elasticsearch 在具有特定字段值的文档中搜索
- python-3.x - 使用 pypff / libpff 导出 PST 和 OST
- jpa - JPA - 加载设置为不可变
- sql - 在 Oracle SQL Developer 中简化 SQL Select 语句
- python - python3中没有为argparse指定子命令时如何显示“参数太少”错误
- python - 导入 pygame 时在 VScode for pylint 中导入失败
- macos - 为什么类没有释放——即析构函数没有被调用?
- php - php。表单插入到数据库后转到下一页
- php - 用于图像的 Slim 框架 3 路径/路由