简体   繁体   English

错误回调中的错误:TestPlugin2 = ReferenceError:找不到变量:登录文件:///android_asset/www/js/cordova-1.6.1.js:276

[英]Error in error callback: TestPlugin2 = ReferenceError: Can't find variable: log at file:///android_asset/www/js/cordova-1.6.1.js:276

Can somebody help me with this: this is my code: 有人可以帮我吗:这是我的代码:

//js // js

var TestPlugin={ 
test:function(name,successCallback,failureCallback){
    console.log("navigator.service.sms smssend: ----------------");
    PhoneGap.exec(successCallback, failureCallback, "TestPlugin", "test", [name]);
}};

TestPlugin.test(
    "hubiao",
        function(){
            alert("success");
        },
        function(e){
            alert("fail");
            log(e);
        }
    );

//Android phonegap // Android phonegap

public class TestPlugin extends Plugin {
@Override
public PluginResult execute(String action, JSONArray data, String callBackId) {

    if ("test".equalsIgnoreCase(action)) {  
        Log.d("DatePickerPluginListener execute", "test");  
        Context context=ctx.getContext();
        String name="";
        JSONObject fileInfo = new JSONObject();
        try {
            name = data.getString(0);
            fileInfo.put("hello", "Android"+name);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        final PluginResult r = new PluginResult(  
                Status.OK,fileInfo); 
        Log.i("TestPlugin", name);
        Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();
        return r;  
    }else{
         Log.d("DatePickerPlugin", "Invalid action : " + action + " passed"); 
         return new PluginResult(Status.INVALID_ACTION); 
    }
}

} }

/// The point: if I add: ///要点:如果我添加:

 Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();

phonegap will give failureCallback, when I remove: 当我删除时,phonegap会给出failureCallback:

 Toast.makeText(context,"User:"+name, Toast.LENGTH_LONG).show();

phonegap will give successCallback. phonegap将给予成功回调。 Why? 为什么? I have no idea.Anyone counld help me? 我不知道。有人会帮助我吗? Thank you very much! 非常感谢你!

Is this not just a simple omission of console. 这不仅仅是console.的简单遗漏console. from console.log() ? console.log()

TestPlugin.test(
    "hubiao",
    function(){
        alert("success");
    },
    function(e){
        alert("fail");
        // log() is undefined.  console.log() is defined!
        console.log(e);
        // Or more likely you want the error message only
        console.log(e.message);
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “初始化网络连接时出错:找不到类”,来源:file:///android_asset/www/cordova.js - “Error initializing Network Connection: Class not found”, source: file:///android_asset/www/cordova.js Phonegap:对象xx在文件中没有方法'exec':///android_asset/www/cordova.js - Phonegap: Object xx has no method 'exec' at file:///android_asset/www/cordova.js 无法在文件:///android_asset/www/apis/camera.js:45读取未定义类型的属性“ DATA_URL” - Can not read propery 'DATA_URL' of undefined type at file:///android_asset/www/apis/camera.js:45 路径“file:/// android_asset /”记录在哪里? - Where is the path “file:///android_asset/” documented? 科尔多瓦插件公开JS变量(Android)(CardFlight) - Cordova Plugin Expose JS Variable (Android) (CardFlight) 无法加载位于 file:///android_asset/file.html 的网页,因为:net::ERR_FILE_NOT_FOUND - The webpage at file:///android_asset/file.html could not be loaded because: net::ERR_FILE_NOT_FOUND 无法构建Cordova Android应用-出现Java错误 - Can't Build Cordova Android App - Java Error Appears Cordova 找不到 $ANDROID_HOME - Cordova can't find $ANDROID_HOME 电话间隙'ReferenceError:找不到变量:设备' - Phone Gap 'ReferenceError: Can't find variable: device' log4js npm错误,log4js配置 - log4js npm error , log4js configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM