我是Cordova和Android应用程序的新手。我们正在课堂上学习它,所以所有这些代码都是复制和粘贴的,目的是学习如何构建项目并在手机上运行它。
所以在calculator.js,calculator.css和index.html下面。
当我尝试构建项目时,我一直在努力。
:app:generateDebugBuildConfig
FAILURE: Build failed with an exception.
FAILED
* What went wrong:
Execution failed for task ':app:generateDebugBuildConfig'.
> Failed to create C:\Users\mrgaw\Desktop\JS workspace\SWD106\MyCordovaApps\calculator\platforms\android\app\build\generated\source\buildConfig\debug\con\example\calculator
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
我认为项目没有构建有问题。我没有得到的是出了什么问题。从来没有真正解释如何调试这个,所以我实际上不太清楚要调试代码的步骤。任何指针,提示或建议都会有所帮助。我基本上都在努力学习如何调试代码,这样我才能知道错误。
function registerEventHandlers() {
zero.addEventListener("click", buttonInputClickHandler, false);
one.addEventListener("click", buttonInputClickHandler, false);
two.addEventListener("click", buttonInputClickHandler, false);
three.addEventListener("click", buttonInputClickHandler, false);
four.addEventListener("click", buttonInputClickHandler, false);
five.addEventListener("click", buttonInputClickHandler, false);
six.addEventListener("click", buttonInputClickHandler, false);
seven.addEventListener("click", buttonInputClickHandler, false);
eight.addEventListener("click", buttonInputClickHandler, false);
nine.addEventListener("click", buttonInputClickHandler, false);
add.addEventListener("click", buttonInputClickHandler, false);
subtract.addEventListener("click", buttonInputClickHandler, false);
multiply.addEventListener("click", buttonInputClickHandler, false);
divide.addEventListener("click", buttonInputClickHandler, false);
point.addEventListener("click", buttonInputClickHandler, false);
equals.addEventListener("click", buttonEqualsClickHandler, false);
clear.addEventListener("click", buttonClearClickHandler, false);
}
// handle click event for buttons that enter and display input
function buttonInputClickHandler(eventArg) {
var display = document.getElementById("display");
display.value = display.value + eventArg.target.value;
}
// handle click event for equals button that evaluates and displays result
function buttonEqualsClickHandler(eventArg) {
var display = document.getElementById("display");
display.value = eval(display.value);
}
// handle click event for clearing display
function buttonClearClickHandler(eventArg) {
var display = document.getElementById("display");
display.value = "";
}

#calculator {
display: block;
width: auto;
border: 2px solid black;
padding: 5px;
}
#display {
display: block;
font-size: x-large;
font-family: monospace;
text-align: right;
margin: auto;
width: calc(100% - 10px);
}
.key {
display: block;
box-sizing: border-box;
-moz-box-sizing: border-box;
width: calc(25% - 10px);
height: 100px;
margin: 5px;
background: yellow;
float: left;
font-size: x-large;
font-family: monospace;
}
#equals {
width: calc(100% - 10px);
}

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/calculator.css">
<title>Calculator</title>
</head>
<body onload="registerEventHandlers()">
<div id="deviceready">
<div id="calculator">
<input type="text" id="display">
<input class='key' type="button" id="seven" value="7">
<input class='key' type="button" id="eight" value="8">
<input class='key' type="button" id="nine" value="9">
<input class='key' type="button" id="divide" value="/">
<input class='key' type="button" id="four" value="4">
<input class='key' type="button" id="five" value="5">
<input class='key' type="button" id="six" value="6">
<input class='key' type="button" id="multiply" value="*">
<input class='key' type="button" id="one" value="1">
<input class='key' type="button" id="two" value="2">
<input class='key' type="button" id="three" value="3">
<input class='key' type="button" id="subtract" value="-">
<input class='key' type="button" id="zero" value="0">
<input class='key' type="button" id="point" value=".">
<input class='key' type="button" id="clear" value="Clear">
<input class='key' type="button" id="add" value="+">
<input class='key' type="button" id="equals" value="=">
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/calculator.js"></script>
</body>
</html>
&#13;
答案 0 :(得分:0)
您不要“调试VS代码”。您可以使用Visual Studio 2017和适用于Apache Cordova的工具进行调试,也可以使用Chrome Remote Dubugging进行调试。查看Debugging Cordova Apps部分。如果您使用VS2017,则应从该站点或Microsoft TACO网站中查看所有指南(也更容易,用于学习和开发)
请注意,无论JS文件中的错误数量如何,都将构建cordova应用程序,因为它们是分开的。如果该应用程序能够生成,但随后会自行关闭,则说明您遇到JS错误,并且在这种情况下必须使用Visual Studio或Chrome浏览器以及仿真器或Android设备开始调试。
此外,我不会在Cordova应用程序中使用带空格的路径。 Cordova可能比JAVA容易,但是对于新手用户来说,了解所有可能的问题可能变得非常复杂,因此从一开始,您实际上必须读很多(多)而更少的代码。