Android: Unable to set getContext () in non-stationary method - API level 23 required

Below is some source code that is called from a non-static method. I get an error

"API level 23 is required for the call (current minimum is 15); android.app.Fragment # getContext"

android.content.Context context = (Context) getContext(); 

How to get a context object?

In explorer> Gradle Scripts> build.gradle object, I see this. Looks like version 23 for me. Am I looking in the right place?

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.test.test" minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.1' compile 'com.android.support:support-v4:23.2.1' } 

It looks like I have Android Studio 1.5.1. I just selected the SettingsActivity project template in Android Studio. And added one class to this standard.

0
android-studio android-api-levels
Apr 20 '16 at 7:05
source share
2 answers

You need to import the android.support.v4.app.Fragment file instead of importing android.support.app.Fragment;

0
Sep 15 '16 at 6:05
source share

One solution is to make this (activity) in (Context) inside the Activity onCreate method.

0
Nov 16 '16 at 3:55
source share



All Articles