簡體   English   中英

如何在VS代碼上調試Cordova代碼

[英]How to debug Cordova code on VS code

我是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> 

您不會“在VS代碼上調試”。 您可以使用Visual Studio 2017和適用於Apache Cordova的工具進行調試,也可以使用Chrome遠程調試。 請查看“ 調試Cordova應用程序”部分。 如果您使用VS2017,則應該從該站點或Microsoft TACO網站中查看所有指南(對於學習和開發也要容易得多

在此處輸入圖片說明

請注意,無論JS文件中的錯誤數量如何,都將構建cordova應用程序,因為它們是分開的。 如果應用程序能夠生成,但隨后會自行關閉,則說明您遇到JS錯誤,並且在這種情況下必須使用Visual Studio或Chrome瀏覽器以及仿真器或Android設備開始調試。

另外,我不會為Cordova應用程序使用帶空格的路徑。 Cordova可能比JAVA容易,但是對於初學者來說,了解所有可能出現的問題可能變得非常復雜,因此從一開始,您實際上必須多讀(少讀)很多代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM