我正在尝试为 Android 平台 2.2 运行基本的 PhoneGap + JQuery Mobile 程序,但我收到应用程序错误“与服务器的连接不成功(file:///android_asset/www/index.html)”当我尝试在 Windows XP 上的 Android Emulator 平台 2.2 中使用 Eclipse 3.7运行应用程序时,在 Android 模拟器中强>。
如果我从 HTML 文件中删除了 JQuery Mobile 的所有引用和语法,则文件会加载,所以我确信我的项目很好,但是我在初始化 JQuery Mobile 时缺少一些东西。我将 PhoneGap 0.9.6 与 JQuery Mobile 版本 *1.0b1* 与 JQuery 版本 1.6.1 一起使用(我还尝试使用带有 JQuery 1.4.4 的 JQM 版本 1.0a2,但出现相同的错误)。
如果我从我的 HTML 文件中删除所有对 JQuery Mobile 的引用,那么我可以在模拟器中加载程序而不会出错。
我查看了网络上的几个示例并按原样尝试了它们,但它们都显示相同的错误。我的文件如下:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap With JQM</title>
<link rel="stylesheet" href="jquery.mobile-1.0b1.min.css" type="text/css" charset="utf-8" />
<script src="jquery-1.6.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.6.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<script src="jquery.mobile-1.0b1.min.js"></script>
</head>
<body onload="init();">
<div data-role="page" data-theme="e">
<div data-role="header">
<h1>PhoneGap with JQM</h1>
</div>
<div data-role="content">
<h1>My Content</h1>
</div>
<div data-role="footer">
<h1>My Footer</h1>
</div>
</body>
</html>
main.js 文件只有:
function init()
{
document.addEventListener("deviceready", deviceInfo, true);
}
我错过了什么?
最佳答案
问题可能是模拟器速度太慢导致网络太慢,及时完成通信。
通过将以下属性添加到 src/com/phonegap/xxx.java
,在 PhoneGap 中设置 60 秒超时:
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
引用资料:
关于javascript - 适用于 Android 的 JQuery Mobile + PhoneGap - 加载 index.html 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6544870/