错误回调错误:TestPlugin2 = ReferenceError:找不到变量:log at file:///android_asset/www/js/cordova-1.6.1.js:276

时间:2012-05-26 16:57:00

标签: java javascript android plugins cordova

有人可以帮我这个: 这是我的代码:

// 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

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

}

/// 重点: 如果我补充:

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

phonegap将给出failureCallback, 当我删除:

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

phonegap将给予successCallback。 为什么?我不知道。任何人都帮助我?非常感谢你!

1 个答案:

答案 0 :(得分:0)

这不仅仅是对来自console.的{​​{1}}的简单遗漏吗?

console.log()