'this' is not available android studio


I have this message during the work with the alert dialogs in the debug window: “‘this’ is not available”

I saw 2 questions similar( this and this) to mine but I do not have Hugo and I could not find the solution.

My gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   compile files('libs/androidsvg-1.2.1.jar')
   compile 'com.android.support:appcompat-v7:24.2.0'
   compile 'com.android.support:design:24.2.0'
   compile 'com.android.support:support-v13:24.2.0'
   compile 'com.android.support:cardview-v7:24.2.0'
   compile 'com.android.support:support-v4:24.2.0'
   compile 'com.android.support:support-vector-drawable:24.2.0'
   compile 'com.android.support:recyclerview-v7:24.2.0'
   testCompile 'junit:junit:4.12'
   compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'

allprojects {
    repositories {

task clean(type: Delete) {
    delete rootProject.buildDir

AND My AlertDialogBuilder Code, which is fails on string .setMultiChoiceItems

AlertDialog.Builder builder = new AlertDialog.Builder(AddKeyActivity.this, R.style.MyAlertDialogStyle);
                    .setMultiChoiceItems(regions, regions_chosen, new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(...) {...}


Actually in the Activity I have one more AlertDialog.Builder, which works perfectly.

Please, can you help me to find the problem.

EDIT: The problem is that in the debug window I see ” regions_chosen – ‘this’ is not available”. The alert dialog is not appearing and the activity crashes.

EDIT2: Initialization of arrays:

final String[] regions = new String[Regions.getRegions().size()];

boolean[] regions_chosen = new boolean[Regions.getRegions().size()];

This is what I saw



String[] regions = new String[Regions.getRegions().size()];


String[] regions = new String[Regions.getRegions().size()];
regions = Regions.getRegions().toArray(regions);

You can optimize the above as,

String[] regions = Regions.getRegions().toArray(new String[0]);

Answered By – K Neeraj Lal

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published