3

I would like to integrate zxing into my app. I'm importing project, set it as library, change target to API 7, download zxing-core-2.2.jar, copy it to /libs and add this jar in Java Building Path as library.

But there are still some errors:

Zxing errors All of them are in switch statements and depend on R.id. for example:

switch (item.getItemId()) {
  case R.id.menu_share:

Eclipse error description:

case expressions must be constant expressions

there is a info dialog:

enter image description here Any idea what I'm doing wrong or how to fix it?

Michał Tajchert
  • 10,333
  • 4
  • 30
  • 47
  • You're not intended to use this is a library. Use core/, not android/. This is the ultimate cause. – Sean Owen Aug 03 '13 at 13:36
  • But I can't import stuff from core/ - I tried import as Existing Android Code into workspace, and Existing project into workspace - both without success. – Michał Tajchert Aug 03 '13 at 14:35

2 Answers2

1

As explained in the dialog you have shown, R.id.menu_settings is now "no longer constant", which means it cannot be used in a switch. the dialog also provides the solution, instead of

switch (item.getItemId()) {
  case R.id.menu_share:
      //do something
      break;
  case xxx:
      ...
}

You should do this:

if(item.getItemId()==R.id.menu_share) {
      //do something
} else if (item.getItemId()==xxx) {
      //do something
}

Just follow the instruction and you should be fine.

Kai
  • 15,284
  • 6
  • 51
  • 82
1

The problem is the source of zxing is not intended to be used as a Library.. Please see the answer by Sean in the below thread.

Zxing project as library in a project won't build

I tried bridling my app within this CaptureActivity project adding my activity and resources and modifying its manifest File accordingly.

Community
  • 1
  • 1
praveena_kd
  • 525
  • 5
  • 15