解决运行时错误 [英] Solve run time errors

查看:151
本文介绍了解决运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实施的Andr​​oid使用PhoneGap的酒吧code扫描仪,但是当我执行程序会显示一些运行时错误(如下图所示)。

有谁知道如何解决这个问题?

  02-03 18:26:35.351:ERROR / AndroidRuntime(876):致命异常:主要
02-03 18:26:35.351:ERROR / AndroidRuntime(876):了java.lang.RuntimeException:无法实例活动ComponentInfo{com.phonegap.plugins.bar$c$cscanner/com.phonegap.plugins.bar$c$cscanner.Bar$c$cScanner}: java.lang.ClassCastException:com.phonegap.plugins.bar codescanner.Bar codeScanner
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.os.Handler.dispatchMessage(Handler.java:99)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.os.Looper.loop(Looper.java:123)
02-03 18:26:35.351:ERROR / AndroidRuntime(876):在android.app.ActivityThread.main(ActivityThread.java:4627)

您好,这是我的源$ C ​​$ C核实并给出了解决方案,这根据的错误。

 包com.phonegap.plugins.bar codescanner;进口org.json.JSONArray;
进口org.json.JSONException;
进口org.json.JSONObject;进口android.app.Activity;
进口android.content.Intent;
进口android.util.Log;进口com.phonegap.api.Plugin;
进口com.phonegap.api.PluginResult;/ **
 *此召唤出斑马线吧code阅读器并返回结果。
 * /
公共类酒吧codeScanner扩展插件{
私有静态最后弦乐TEXT_TYPE =TEXT_TYPE;
私有静态最后弦乐EMAIL_TYPE =EMAIL_TYPE;
私有静态最后弦乐PHONE_TYPE =PHONE_TYPE;
私有静态最后弦乐SMS_TYPE =SMS_TYPE;公共静态最终诠释REQUEST_ code = 0x0ba7c0de;公共字符串回调;/ **
 *构造函数。
 * /
公共酒吧codeScanner(){
}/ **
 *执行该请求并返回PluginResult。
 *
 * @参数动作的动作来执行。
 *为插件参数@param ARGS JSONArray。
 * @参数callbackId回调成JavaScript时使用的回调ID。
 * @返回一个PluginResult用状态和消息对象。
 * /
公共PluginResult执行(串动,JSONArray ARGS,弦乐callbackId){
    this.callback = callbackId;    如果(action.equals(EN code)){
        的JSONObject物镜= args.optJSONObject(0);
        如果(OBJ!= NULL){
            字符串类型= obj.optString(类型);
            字符串数据= obj.optString(数据);            //如果类型为null,则强制类型为文本
            如果(类型== NULL){
                键入= TEXT_TYPE;
            }            如果(数据== NULL){
                返回新PluginResult(PluginResult.Status.ERROR,用户没有指定的数据连接code);
            }            EN code(类型,数据);
        }其他{
            返回新PluginResult(PluginResult.Status.ERROR,用户没有指定的数据连接code);
        }
    }
    否则,如果(action.equals(扫描)){
        扫描();
    }其他{
        返回新PluginResult(PluginResult.Status.INVALID_ACTION);
    }
    PluginResult R =新PluginResult(PluginResult.Status.NO_RESULT);
    r.setKeepCallback(真);
    返回ř;
}
/ **
 *启动意图扫描和德code酒吧code。
 * /
公共无效扫描(){
    意图int​​entScan =新意图(com.phonegap.plugins.bar codescanner.SCAN);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);    this.ctx.startActivityForResult((插件)这一点,intentScan,REQUEST_ code);
}/ **
 *酒吧code扫描仪意图完成时调用
 *
 * @参数要求code原本提供给startActivityForResult请求code()
 *让您确定谁这个结果是从哪里来的。
 * @参数结果code通过它的setResult由儿童活动返回的整数结果code()。
 * @参数意图的意图,其可以结果数据返回给调用者(各种数据可以连接到意图额外)。
 * /
公共无效的onActivityResult(INT申请code,INT结果code,意图意图){
    如果(要求code == REQUEST_ code){
        如果(结果code == Activity.RESULT_OK){
            JSONObject的OBJ =新的JSONObject();
            尝试{
                obj.put(文字,intent.getStringExtra(SCAN_RESULT));
                obj.put(格式,intent.getStringExtra(SCAN_RESULT_FORMAT));
                obj.put(取消,FALSE);
            }赶上(JSONException E){
                //Log.d(LOG_TAG,这应该不会发生);
            }
            this.success(新PluginResult(PluginResult.Status.OK,OBJ),this.callback);
        }如果(结果code == Activity.RESULT_CANCELED){
            JSONObject的OBJ =新的JSONObject();
            尝试{
                obj.put(文字,);
                obj.put(格式化,);
                obj.put(取消,真正的);
            }赶上(JSONException E){
                //Log.d(LOG_TAG,这应该不会发生);
            }
            this.success(新PluginResult(PluginResult.Status.OK,OBJ),this.callback);
        }其他{
            this.error(新PluginResult(PluginResult.Status.ERROR),this.callback);
        }
    }
}/ **
 *发起酒吧code EN code。
 * @参数数据的数据连接在酒吧code code
 * @参数DATA2
 * /
公共无效连接code(字符串类型,字符串数据){
    意图int​​entEn code =新意图(com.phonegap.plugins.bar codescanner.EN code);
    intentEn code.putExtra(EN code_TYPE型);
    intentEn code.putExtra(EN code_DATA的数据);    this.ctx.startActivity(intentEn code);
}
}


解决方案

我想你可能有一些在你的Andr​​oidManifest.xml文件搞砸了。类com.phonegap.plugins.bar codescanner.Bar codeScanner应该在你的plugins.xml文件设置。你有没有关于建立律师codeScanner阅读我的教程?

http://simonmacdonald.blogspot.com/2011/12/installing-bar$c$c-plugin-for-phonegap.html

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);
}
}

解决方案

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

这篇关于解决运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆