Android Barcode Scanner

2020-08-08 01:49发布

问题:

I am using Biggu barcode library.

Packaged library has been listed everything using demo and sample application.

But I am getting no class definition found error

     java.lang.NoClassDefFoundError: com.biggu.scannerdemo.ScannerActivity

But the class is in package and manifest file lists all the activities. Build path has biggu_scanner-1.1.0.jar file in its path.

package com.biggu.scannerdemo;

import com.biggu.barcodescanner.client.android.Intents;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Demo extends Activity {

private static final int SCANNER_REQUEST_CODE = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button)findViewById(R.id.btn);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent intent = new Intent(v.getContext(), com.biggu.scannerdemo.ScannerActivity.class);
            intent.putExtra(Intents.Preferences.ENABLE_BEEP, true);
            intent.putExtra(Intents.Preferences.ENABLE_VIBRATE, true);

            ((Activity)v.getContext()).startActivityForResult(intent, SCANNER_REQUEST_CODE);
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK && requestCode == SCANNER_REQUEST_CODE) {

        Bundle extras = data.getExtras();
        String result = extras.getString("SCAN_RESULT");
        TextView textView = (TextView)findViewById(R.id.txt);
        textView.setText(result);
    }
}}

ScannerActivity is having the below code

package com.biggu.scannerdemo;

import com.biggu.barcodescanner.client.android.CaptureActivity;

public class ScannerActivity extends CaptureActivity {

@Override
public int get_R_id_preview_view() {

    return R.id.preview_view;
}

@Override
public int get_R_id_viewfinder_view() {

    return R.id.viewfinder_view;
}

@Override
public int get_R_layout_scanner() {

    return R.layout.scanner;
}

@Override
public int get_R_raw_beep() {

    return R.raw.beep;
}
}

Android manifest file

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.biggu.scannerdemo"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Demo"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".ScannerActivity"
        android:label="Scanner Activity" android:screenOrientation="landscape"
        android:configChanges="orientation|keyboardHidden" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    </activity>

</application>
<uses-sdk android:minSdkVersion="4" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

Tried everything to set right Could anyone let me know what could be the wrong in the code. Looking forward to your reply.thanks.

回答1:

You must make sure that your lib is exported when building the APK.

In Project properties > Java Build Path > Order and Export => check your lib



回答2:

You need to add the library in the project preferences.