Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ/Android -> "java: constant expression required" on case R.id.viewId

When I try to build my Android project in IntelliJ i get error´s on every switch statement which cases use Id´s out of the R.java.

Example:

switch (item.getItemId()) {

  case android.R.id.home:
    NavUtils.navigateUpTo(this, DashboardActivity.upIntent(this));
    return true;

  case R.id.orders_options_add:
    handleAddItem();
    return true;

  case R.id.orders_options_reorder:
    handleReorder();
    finish();
    return true;
}

Does anyone know how to solve this problem?

like image 904
Ostkontentitan Avatar asked Mar 06 '13 12:03

Ostkontentitan


1 Answers

Resource ids are not constants in a library project since ADT version 14, so you can't use them in switch statement. Just use if () {} else if () {} ... instead.

You can find more detailed information here.

like image 88
Vladimir Mironov Avatar answered Oct 22 '22 05:10

Vladimir Mironov