A
A
Andrey2020-02-21 18:43:19
Android
Andrey, 2020-02-21 18:43:19

Why AppCompatActivity error when running on Android 7x?

Greetings, I recently started to master android-studio and ran into one problem. I create a project out of the box with an Empty activity and immediately observe a strange thing - there is no ActionBar on the markup, although it is present when the application is

5e4ff891c86a7819687130.png

launched.

Log pastebin

The error refers to line number 10, but everything seems to be fine with it.

package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main) // <----- Line 10
    }
}


Here is the project structure:
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 24
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}


What could be the problem?

PS.
If the MainActivity.kt file inherits not from AppCompatActivity() but from Activity(), then the error disappears, but then there is a problem with the View and it is not possible to create (for example) a Snackbar.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2020-02-22
@YuryBorodkin

This panel shows the result for a particular topic.
Where you have a button labeled `AppTheme`, select the theme of your application (you can see what it is called in res/values/styles.xml) and what you will have at startup should be displayed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question