【发布时间】:2026-02-14 15:30:01
【问题描述】:
我的问题是关于 JaneaSystems 的移动端 Node js。我有一个网络应用程序,我将其转换为科尔多瓦应用程序。我已按照入门教程中给出的所有说明进行操作
https://code.janeasystems.com/nodejs-mobile/getting-started-cordova
但是,在 android 模拟器中从 js/index.js 触发 nodejs 时,我收到错误消息“Initialization failed: java.io.FileNotFoundException: www\nodejs-project/main.js强>”
我的 index.js 文件如下:
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
this.receivedEvent('deviceready');
startNodeProject();
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
app.initialize();
function channelListener(msg) {
console.log('[cordova] received:' + msg);
}
function startupCallback(err) {
if (err) {
console.log(err);
} else {
console.log ('Node.js Mobile Engine Started');
nodejs.channel.send('Hello from Cordova!');
}
};
function startNodeProject() {
nodejs.channel.setListener(channelListener);
nodejs.start('main.js', startupCallback);
// To disable the stdout/stderr redirection to the Android logcat:
// nodejs.start('main.js', startupCallback, { redirectOutputToLogcat: false });
};
我的main.js如下:
const cordova = require('cordova-bridge');
cordova.channel.on('message', function (msg) {
console.log('[node] received:', msg);
cordova.channel.send('Replying to this message: ' + msg);
});
当我执行命令 cordova build android 时,会在 /platforms/android/assets 下创建一个名为“file.list”的文件,其内容为
www\nodejs-project/main.js
即使我手动将上面的内容更改为www\nodejs-project\main.js,我仍然会收到 FileNotFound 异常。
谁能告诉我我缺少什么,因为文件 main.js 存在于 nodejs-project 下?
如果需要任何详细信息,请告诉我,因为我尽量做到详尽。
【问题讨论】:
标签: android node.js cordova gradle mobile