2014-09-24 102 views
1

我想添加QRCode到我的android應用程序。QrCode掃描儀「無法解析符號CaptureActivity」

我正在使用Android Studio 8.1。

我下載的斑馬線從Maven倉庫core.jar添加文件(http://repo1.maven.org/maven2/com/google/zxing/core/3.1.0/

我添加以下行到我的清單XML文件:

<uses-permission android:name="android.permission.CAMERA" /> 
<activity 
android:name="com.google.zxing.client.android.CaptureActivity" 
android:screenOrientation="landscape" > 
</activity> 

然後我加了jar文件到 「LIB」 文件夾,我添加爲圖書館gradle這個build文件:

編譯文件( '庫/核心-3.1.0.jar')

我開了以下活動:

public class QrCodeReader extends Activity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_qrcode); 
     HandleClick hc = new HandleClick(); 
     findViewById(R.id.butQR).setOnClickListener(hc); 
     findViewById(R.id.butProd).setOnClickListener(hc); 
     findViewById(R.id.butOther).setOnClickListener(hc); 
    } 
    private class HandleClick implements View.OnClickListener { 
     public void onClick(View arg0) { 
      Intent intent = new Intent(getApplicationContext(),CaptureActivity.class); 
      intent.setAction("com.google.zxing.client.android.SCAN"); 
      intent.putExtra("SAVE_HISTORY", false); 
      startActivityForResult(intent, 0); 


     } 
    } 
    public void onActivityResult(int requestCode, int resultCode, Intent intent) { 
     if (requestCode == 0) { 
      TextView tvStatus=(TextView)findViewById(R.id.tvStatus); 
      TextView tvResult=(TextView)findViewById(R.id.tvResult); 
      if (resultCode == RESULT_OK) { 
       tvStatus.setText(intent.getStringExtra("SCAN_RESULT_FORMAT")); 
       tvResult.setText(intent.getStringExtra("SCAN_RESULT")); 
      } else if (resultCode == RESULT_CANCELED) { 
       tvStatus.setText("Press a button to start a scan."); 
       tvResult.setText("Scan cancelled."); 
      } 
     } 
    } 

} 

現在我越來越「不能解決符號CaptureActivity」錯誤,我該如何解決這個問題?

問候

編輯:

我添加下面的文件和該錯誤固定

編譯的文件( '庫/機器人核-3.1.0.jar') 編譯的文件(「庫/android-integration-3.1.0.jar')

但我得到以下錯誤:

拋出java.lang.ClassNotFoundException:未找到類「com.google.zxing.client.android.CaptureActivity」我該如何解決這個問題?

+0

只有三個原因你會得到這個錯誤: 該類真正不存在。如果您使用的是官方示例中的代碼並獲取該代碼,請確保您擁有庫的最新版本 您尚未將jar添加到構建路徑。要解決這個問題,請右鍵單擊Eclipse中的jar,然後執行構建路徑►添加到構建路徑。 您的jar不在/ libs文件夾中。當你將jar添加到構建路徑時會發生這種情況,但ADT的新版本需要它在/ libs中。把它放在那裏並重新添加到構建路徑。 – 2014-09-24 09:37:56

回答

1

只有三個原因,你永遠不會得到這個錯誤:

類真正沒有按不存在。如果您使用的是官方示例中的代碼並獲取該代碼,請確保您擁有庫的最新版本

您尚未將jar添加到您的構建路徑。要解決這個問題,請右鍵單擊Eclipse中的jar,然後執行構建路徑►添加到構建路徑。

您的jar不在/ libs文件夾中。當你將jar添加到構建路徑時會發生這種情況,但ADT的新版本需要它在/ libs中。把它放在那裏並重新添加到構建路徑。

0

在捕獲活動中添加意圖過濾器。

<intent-filter> 
    <action android:name="com.google.zxing.client.android.SCAN" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
+0

我添加了,但我得到相同的錯誤,生成失敗:錯誤:(27,63)錯誤:找不到符號類CaptureActivity – onder 2014-09-24 09:29:14

-1

一次參考這個鏈接 http://wahidgazzah.olympe.in/integrating-zxing-in-your-android-app-as-standalone-scanner/

在AndroidManifest.xml中添加此

<activity 
    android:name="com.google.zxing.client.android.CaptureActivity" 
    android:configChanges="orientation|keyboardHidden" 
    android:screenOrientation="landscape" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
    android:windowSoftInputMode="stateAlwaysHidden" > 
    <intent-filter> 
     <action android:name="com.google.zxing.client.android.SCAN" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 
+0

我添加,但我得到相同的錯誤,生成失敗:錯誤:(27,63)錯誤:找不到符號類CaptureActivity – onder 2014-09-24 09:30:20

+0

java.lang.ClassNotFoundException:未找到類「com.google.zxing.client.android.CaptureActivity」我該如何解決這個問題 – onder 2014-09-24 12:29:43

1

您不打算在您的應用程序中使用CaptureActivity。由於這個原因,它不在core中,這就是爲什麼你的應用程序找不到它。

您的代碼很混亂,因爲您似乎想要通過Intent進行整合,但是您不需要android或甚至core中的任何代碼。相反,你應該按照指示https://github.com/zxing/zxing/wiki/Scanning-Via-Intent

+0

如果我使用下面的代碼,它可以工作,但我得到這個消息:安裝條碼掃描儀?我想在我的應用程序中使用qrcode掃描儀,我不想安裝任何應用程序。我可以這樣做嗎?謝謝IntentIntegrator integrator = new IntentIntegrator(QrCodeReader.this); integrator.initiateScan(); – onder 2014-09-25 09:25:26

+0

然後你不想使用'Intent's。您需要編寫自己的掃描應用程序;請不要克隆我們的。但是如果你願意的話,你應該重用'core /'並重用'android /'源代碼的一部分。只是不要複製和粘貼。我們已經有很多問題了。 – 2014-09-25 11:56:27