Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zxing 2.2 and R.id error

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?

like image 585
Michał Tajchert Avatar asked Dec 14 '25 16:12

Michał Tajchert


2 Answers

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.

like image 160
Kai Avatar answered Dec 17 '25 07:12

Kai


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.

like image 40
praveena_kd Avatar answered Dec 17 '25 07:12

praveena_kd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!