Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android resource IDs suddenly not final, fields cannot be resolved

I'm working on a new-old project... I'm making it for a different country market, and when i copyed my code from an old project it shows some mistake like MIGRATE ANDROID CODE (As of ADT 14, resource fields cannot be used as switch cases.) This happens for a resourses that are in strings.xml file and for layout. But it doesn't give me some posible fix... how can i fix it???? Here is code:

 @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            //Here is mistake
            setContentView(R.layout.main);

          //Kreira AlertDialog sa dva dugmeta koji ce se pojaviti pri aktiviranju aplikacije
            ad = new AlertDialog.Builder(this).create();
//And HERE
            ad.setTitle(getString(R.string.vasa_trenutna_lokacija));
            //And HERE
ad.setMessage(getString(R.string.da_bi_ste_koristili_aplikaciju));
            //And HERE
            ad.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dozvoli), new DialogInterface.OnClickListener() {

            //Klikom na dugme Dozvoli otvara se novi prozor
            @Override
            public void onClick(DialogInterface ad, int which) {
                Intent i = new Intent(NiskiMerakActivity.this, TrenutnaLokacija.class);             
                startActivity(i);
                finish();
                }
            });

            ad.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.ne_dozvoli),new DialogInterface.OnClickListener() {

            //Klikom na dugme Ne dozvoli aplikacija se zatvara
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();

                }
            });
like image 615
Jovan Avatar asked Oct 25 '11 13:10

Jovan


2 Answers

Quoting http://tools.android.com/tips/non-constant-fields

The solution for this is simple: Convert the switch statement into an if-else statement.

Since your code snippet above does not appear to have a switch() statement, yet your question refers to a switch() statement, I assume you have the wrong code.

like image 198
CommonsWare Avatar answered Oct 20 '22 09:10

CommonsWare


if your switch-case of the ids is inside a library, sadly the new ADT versions don't support it.

However, you can convert it easily to if-else , as shown on Google's website:

http://tools.android.com/tips/non-constant-fields
like image 9
android developer Avatar answered Oct 20 '22 10:10

android developer