2014-07-20 106 views
0

我用ZXing使用條碼閱讀器。 一切正常,直到我加入動作條到我的應用程序(添加android-support-v7-appcompat.jar到依賴性),然後當我點擊按鈕,打開條碼掃描器:ZXing條碼閱讀器錯誤

public void btnBarcode_Click(View view) { 
    IntentIntegrator.initiateScan(this); 
} 

我的應用程序退出與此日誌:

07-20 10:34:03.690: E/AndroidRuntime(23805): FATAL EXCEPTION: main 
07-20 10:34:03.690: E/AndroidRuntime(23805): java.lang.IllegalStateException: Could not execute method of the activity 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.view.View$1.onClick(View.java:3606) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.view.View.performClick(View.java:4211) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.view.View$PerformClick.run(View.java:17446) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.os.Handler.handleCallback(Handler.java:725) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.os.Handler.dispatchMessage(Handler.java:92) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.os.Looper.loop(Looper.java:153) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.app.ActivityThread.main(ActivityThread.java:5299) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at java.lang.reflect.Method.invokeNative(Native Method) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at java.lang.reflect.Method.invoke(Method.java:511) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at dalvik.system.NativeStart.main(Native Method) 
07-20 10:34:03.690: E/AndroidRuntime(23805): Caused by: java.lang.reflect.InvocationTargetException 
07-20 10:34:03.690: E/AndroidRuntime(23805): at java.lang.reflect.Method.invokeNative(Native Method) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at java.lang.reflect.Method.invoke(Method.java:511) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.view.View$1.onClick(View.java:3601) 
07-20 10:34:03.690: E/AndroidRuntime(23805): ... 11 more 
07-20 10:34:03.690: E/AndroidRuntime(23805): Caused by: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:822) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at pl.looksok.listviewdemo.IntentIntegrator.initiateScan(IntentIntegrator.java:179) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at pl.looksok.listviewdemo.IntentIntegrator.initiateScan(IntentIntegrator.java:140) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at pl.looksok.listviewdemo.IntentIntegrator.initiateScan(IntentIntegrator.java:102) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at pl.looksok.listviewdemo.AddNewPerson.btnBarcode_Click(AddNewPerson.java:107) 
07-20 10:34:03.690: E/AndroidRuntime(23805): ... 14 more 

它與「android-support-v7-appcompat.jar」還是沒有關係?

回答

2
07-20 10:34:03.690: E/AndroidRuntime(23805): Caused by: java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode 
07-20 10:34:03.690: E/AndroidRuntime(23805): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:822) 
07-20 10:34:03.690: E/AndroidRuntime(23805): at pl.looksok.listviewdemo.IntentIntegrator.initiateScan(IntentIntegrator.java:179) 

我面臨這個問題之前,但我能勉強記得,但我認爲你應該在圖書館挖掘和改變其啓動的活動的結果在斑馬線庫的請求的代碼,它可能大於65535

+0

我該怎麼做? – mahdi

+0

@mahdi:跟蹤initiateScan()函數。錯誤發生在:在pl.looksok.listviewdemo.IntentIntegrator.initiateScan(IntentIntegrator.java:179) –

+2

正確,由於片段API施加限制,Android不允許請求代碼大於65535。您可以看到該庫的默認大小正確:https://github.com/zxing/zxing/blob/master/android-integration/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java# L112 –