First of all check if your project is using androidx or android support library.
Check gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
If it contains the above lines, it is using androidx with an old code from some old tutorial.
In build.gradle (module:app)
Use
implementation 'androidx.appcompat:appcompat:1.0.0'
Instead of
compile 'com.android.support:appcompat-v7:28.0.0'
Also in MainActivity.java :
Use
import androidx.appcompat.app.AppCompatActivity;
instead of :
import android.support.v7.app.AppCompatActivity;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…