当前位置: 首页 > 知识库问答 >
问题:

Android-无法实例化一个或多个类

桂德义
2023-03-14

我目前正在开发一个Android用户界面,并遇到了以下问题。

基于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>

参考资料:

  • 以下类无法实例化:-android.support.v7.widget.工具栏
  • 找不到以下类:-android.support.design.widget.TextInputLayout
  • Android自定义动作栏示例教程
  • Android无法实例化一个或多个类

共有1个答案

丁震博
2023-03-14

您所使用的所有支持库都需要相同的版本。现在,你可以更换这条线

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

具有

implementation 'com.android.support:appcompat-v7:27.1.0'

还要将您的compileSdkVersionTarget etSdkVersion版本更改为27。

 类似资料:
  • 问题内容: 我有一个正在运行的项目,并且所有xml文件都向我显示错误消息。该程序仍然有效。 我清理了缓存,并使用了无效的缓存和重新启动。 这里是完整的消息: 以下类无法实例化android.support.v7.widget.AppCompatTextView 提示:在IDE中显示时,在自定义视图中使用View.isInEditMode()可以跳过代码或显示示例数据。 问题答案: 在, 改变从主题

  • 有人能解释一下下面的代码是如何毫无例外地工作的吗。我在想,当为星期天创建新实例时,它也会为星期一(星期天内)创建一个新实例,然后再为星期天(星期一内)创建一个新实例,以此类推。。。类似递归的东西,因为它们都是课程周的一部分。但我的理解是错误的,因为下面的代码运行良好。 我有这个疑问,当我读到java枚举。

  • registration-server.yml为: docker-compose文件为: eureka的两个实例,即server-1和server-2都运行良好。但他们没有互相注册。 有关更多信息,已附上屏幕截图:Server-1 server-2

  • 问题内容: 我的代码中需要一个单例。我用Java实现了它,并且效果很好。我这样做的原因是为了确保在多种环境中只有一个此类的实例。 但是现在我想用单元测试在本地测试我的Singleton对象。因此,我需要模拟此Singleton的另一个实例(该对象可能来自另一个设备)。那么是否有可能第二次实例化Singleton以进行测试,还是我必须对其进行模拟? 我不确定,但是我认为可以通过使用其他类加载器来实现

  • 问题内容: 我需要同时运行两个AudioTrack实例。它们必须单独运行,因为我以不同的可变采样率播放它们。我发现,如果我在同一线程中运行它们,它们将“轮流”运行。我在各自的线程中运行它们,但是音频断断续续。 关于使两个实例更好玩的任何想法?如果没有,那么即使我想以不同的采样率播放两个短缓冲区,也有一些技巧将它们混合在一起。 问题答案: 我有4个音轨同时播放,它们似乎播放得很好。在HTC Desi