javascript 适用于 Android 的 JQuery Mobile + PhoneGap - 加载 index.html 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6544870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery Mobile + PhoneGap for Android - Error loading index.html
提问by Rags
I am trying to get a basic PhoneGap + JQuery Mobileprogram running for Android platform 2.2, but I am getting an Application Error "The Connection to the server was unsuccessful (file:///android_asset/www/index.html)" in the Android Emulator when I try to run the application in Android Emulator platform 2.2 on Windows XP, with Eclipse 3.7.
我正在尝试为Android 平台 2.2运行一个基本的PhoneGap + JQuery Mobile程序,但是我在当我尝试使用Eclipse 3.7在Windows XP上的 Android Emulator 平台 2.2 中运行应用程序时,Android Emulator 。
The file loads if I remove all references and syntax of JQuery Mobile from the HTML file, so I am certain that my project is fine but there's something I am missing with initialization of JQuery Mobile. I am using PhoneGap 0.9.6with JQuery Mobile version *1.0b1*with JQuery version 1.6.1(I also tried with JQM Version 1.0a2 with JQuery 1.4.4 but with the same error).
如果我从 HTML 文件中删除 JQuery Mobile 的所有引用和语法,则会加载该文件,所以我确信我的项目没问题,但是在 JQuery Mobile 的初始化中我缺少一些东西。我正在使用PhoneGap 0.9.6和JQuery Mobile 版本 * 1.0b1*和JQuery 1.6.1(我也尝试过 JQM 版本 1.0a2 和 JQuery 1.4.4,但有同样的错误)。
If I remove all references to JQuery Mobile from my HTML file then I am able to load the program in the emulator without errors.
如果我从我的 HTML 文件中删除了对 JQuery Mobile 的所有引用,那么我就可以在模拟器中加载程序而不会出错。
I looked at several examples on the web and tried them as they are, but all of them show the same error. My files are as:
我查看了网络上的几个示例并按原样尝试了它们,但所有示例都显示相同的错误。我的文件如下:
<!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>
The main.js file has only:
main.js 文件只有:
function init()
{
document.addEventListener("deviceready", deviceInfo, true);
}
What am I missing?
我错过了什么?
回答by Moog
The problem is likely due to the speed of the emulator so the network is too slow complete the communication in a timely fashion.
问题很可能是由于模拟器的速度太慢导致无法及时完成通信。
Set a 60 second timeout in PhoneGap by adding the following property to src/com/phonegap/xxx.java
:
通过将以下属性添加到 PhoneGap 中,设置 60 秒超时src/com/phonegap/xxx.java
:
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
References:
参考:
回答by Roy M J
The above solution is for java based code. However OP is for javascript/jqueryand phonegap. The following has helped me solve the issue.
上述解决方案适用于基于 Java 的代码。但是 OP 适用于javascript/jquery和phonegap。以下帮助我解决了这个问题。
In config.xml, add :
在config.xml 中,添加:
<preference name="splash-screen-duration" value="25000" />
<!-- Increase the value until the error is solved-->
The REAL problem here is that PhoneGap has an initial page load timeout of 20 seconds. If your page takes more than that ammount of time, you get this message.
这里真正的问题是 PhoneGap 的初始页面加载超时为 20 秒。如果您的页面花费的时间超过该数量,您会收到此消息。
Application Error - The connection to the server was unsuccessful.
(file:///android_asset/www/index.html)