Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:45:31+00:00 2026-05-29T09:45:31+00:00

I am implementing a bar code scanner in Android using PhoneGap, but when I

  • 0

I am implementing a bar code scanner in Android using PhoneGap, but when I execute the program it displays a number of runtime errors (shown below).

Does anyone know how to solve this problem?

02-03 18:26:35.351: ERROR/AndroidRuntime(876): FATAL EXCEPTION: main
02-03 18:26:35.351: ERROR/AndroidRuntime(876): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.phonegap.plugins.barcodescanner/com.phonegap.plugins.barcodescanner.BarcodeScanner}: java.lang.ClassCastException: com.phonegap.plugins.barcodescanner.BarcodeScanner
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.os.Looper.loop(Looper.java:123)
02-03 18:26:35.351: ERROR/AndroidRuntime(876):     at android.app.ActivityThread.main(ActivityThread.java:4627)

hi this is my source code verify and give the solution for it according to errors.

package com.phonegap.plugins.barcodescanner;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

/**
 * This calls out to the ZXing barcode reader and returns the result.
 */
public class BarcodeScanner extends Plugin {
private static final String TEXT_TYPE = "TEXT_TYPE";
private static final String EMAIL_TYPE = "EMAIL_TYPE";
private static final String PHONE_TYPE = "PHONE_TYPE";
private static final String SMS_TYPE = "SMS_TYPE";

public static final int REQUEST_CODE = 0x0ba7c0de;

public String callback;

/**
 * Constructor.
 */
public BarcodeScanner() {
}

/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArray of arguments for the plugin.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              A PluginResult object with a status and message.
 */
public PluginResult execute(String action, JSONArray args, String callbackId) {
    this.callback = callbackId;

    if (action.equals("encode")) {
        JSONObject obj = args.optJSONObject(0);
        if (obj != null) {
            String type = obj.optString("type");
            String data = obj.optString("data");

            // If the type is null then force the type to text
            if (type == null) {
                type = TEXT_TYPE;
            }

            if (data == null) {
                return new PluginResult(PluginResult.Status.ERROR, "User did not specify data to encode");                                            
            }

            encode(type, data);                    
        } else {
            return new PluginResult(PluginResult.Status.ERROR, "User did not specify data to encode");                    
        }
    }
    else if (action.equals("scan")) {
        scan();
    } else {
        return new PluginResult(PluginResult.Status.INVALID_ACTION);
    }
    PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
    r.setKeepCallback(true);
    return r;
}


/**
 * Starts an intent to scan and decode a barcode.
 */
public void scan() {
    Intent intentScan = new Intent("com.phonegap.plugins.barcodescanner.SCAN");
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);

    this.ctx.startActivityForResult((Plugin) this, intentScan, REQUEST_CODE);
}

/**
 * Called when the barcode scanner intent completes
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param intent            An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put("text", intent.getStringExtra("SCAN_RESULT"));
                obj.put("format", intent.getStringExtra("SCAN_RESULT_FORMAT"));
                obj.put("cancelled", false);
            } catch(JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        } if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put("text", "");
                obj.put("format", "");
                obj.put("cancelled", true);
            } catch(JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        } else {
            this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
        }
    }
}

/**
 * Initiates a barcode encode. 
 * @param data  The data to encode in the bar code
 * @param data2 
 */
public void encode(String type, String data) {
    Intent intentEncode = new Intent("com.phonegap.plugins.barcodescanner.ENCODE");
    intentEncode.putExtra("ENCODE_TYPE", type);
    intentEncode.putExtra("ENCODE_DATA", data);

    this.ctx.startActivity(intentEncode);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:45:32+00:00Added an answer on May 29, 2026 at 9:45 am

    I think you may have something screwed up in your AndroidManifest.xml file. The class com.phonegap.plugins.barcodescanner.BarcodeScanner should be setup in your plugins.xml file. Did you read my tutorial on setting up the BarcodeScanner?

    http://simonmacdonald.blogspot.com/2011/12/installing-barcode-plugin-for-phonegap.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the below code I am implementing my own Navigation Bar. For some reason
My form doesn't have a title bar, so I am implementing the code to
Already finished implementing the player. I want to implement the progress bar. But I
I'm using urllib.urlretrieve to download a file, and implementing a download progress bar using
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Can I use progress bar in android, without the thread? HERE IS CODE OF
Im implementing a combined tab bar and navigation programatically, using the apple documentation ,
I'm implementing a java TCP/IP Server using ServerSocket to accept messages from clients via
So I'm having trouble implementing a search bar in my app. The methods find
Given the code below the method foo should compare operator-wise a given parameter bar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.