build.gradle
Код: Выделить всё
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Код: Выделить всё
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
mavenLocal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
mavenLocal()
}
}
rootProject.name = "Example"
include ':app'
Код: Выделить всё
plugins {
id 'com.android.application'
}
android {
compileSdk 34
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example"
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Код: Выделить всё
package com.example;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Set context
Context ctx = getApplicationContext();
}
}
Код: Выделить всё
Cannot resolve method 'getApplicationContext' in 'MainActivity'
Приложение компилируется и запускается без каких-либо ошибок, поэтому проблема, безусловно, связана с самой IDE. Я пробовал несколько перезапусков, аннулировал кеш и перестраивал проект, но ничего не помогло. Что является причиной этого?
Подробнее здесь: https://stackoverflow.com/questions/785 ... atactivity
Мобильная версия