3

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'
}

AND

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

buildscript {
    repositories {
        jcenter()
    }
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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);
            builder.setTitle(R.string.choose_region)
                    .setMultiChoiceItems(regions, regions_chosen, new DialogInterface.OnMultiChoiceClickListener() {
@Override 
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()];
Regions.getRegions().toArray(regions);

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

This is what I saw

Gangnus
  • 24,044
  • 16
  • 90
  • 149
Lisa Semyonova
  • 117
  • 2
  • 13

1 Answers1

2

Change

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

to,

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]);
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33