PhoneGap 1.8.1 - super.loadUrl("file:///android_asset/www/index.html") 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11132852/
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
PhoneGap 1.8.1 - super.loadUrl("file:///android_asset/www/index.html") issue
提问by King Goeks
I'd just download and use latest version of phonegap : v.1.8.1
我只是下载并使用最新版本的 phonegap:v.1.8.1
as usual, I replace the setContentView(R.layout.main)
line with super.loadUrl("file:///android_asset/www/index.html");
像往常一样,我setContentView(R.layout.main)
用super.loadUrl("file:///android_asset/www/index.html");
When I test my "hello world" application, it will always force close. The app can't run properly. But if i change back the line into setContentView(R.layout.main)
, the app will run properly and there is no problem (for the application). The real problem is, the application not load the index.html because there is no super.loadUrl("file:///android_asset/www/index.html");
line.
当我测试我的“hello world”应用程序时,它总是会强制关闭。该应用程序无法正常运行。但是,如果我将线路改回setContentView(R.layout.main)
,应用程序将正常运行并且没有问题(对于应用程序)。真正的问题是,应用程序没有加载 index.html 因为没有super.loadUrl("file:///android_asset/www/index.html");
行。
here is my code :
这是我的代码:
package com.urfinder.android;
import android.os.Bundle;
import org.apache.cordova.DroidGap;
public class URFinderActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}`
Anyone can give me some advise about this? Thank you :)
任何人都可以给我一些建议吗?谢谢 :)
回答by artemkaxboy
Change the class's extend from Activity
to DroidGap
.
将类的扩展从 更改Activity
为DroidGap
。
回答by Faizal
1) In your html file, have u put this line in <head>
?
1)在你的html文件中,你有没有把这一行放在<head>
?
<script type="text/javascript" charset="utf-8" src="cordova-1.8.1.js"></script>
2) Add this line on top of your activity
2)将此行添加到您的活动之上
import org.apache.cordova.*;
3) Have you copy cordova-1.8.1.jar
from your Cordova download earlier into folder /libs
3)您是否将之前cordova-1.8.1.jar
从 Cordova 下载的内容复制到文件夹中/libs
4) Have you configure project Build Path?
4)您是否配置了项目构建路径?
Right click on the
/libs
folder and go to Build Paths/ > Configure Build Path.... Then, in the Libraries tab, addcordova-1.8.1.jar
to the project
右键单击该
/libs
文件夹并转到Build Paths/ > Configure Build Path.... 然后,在 Libraries 选项卡中,添加cordova-1.8.1.jar
到项目
5) Have you copy cordova.xml
and plugins.xml
file from your Cordova download earlier into folder /res/xml
5)您是否将之前从 Cordova 下载的文件复制cordova.xml
并plugins.xml
归档到文件夹中/res/xml
This is your check list. Hope it help.
这是您的检查清单。希望有帮助。
回答by sharavan
Probably you have created the WWW directory in uppercase letters... Try the code shown below.
可能您已经用大写字母创建了 WWW 目录...试试下面显示的代码。
super.loadUrl("file:///android_asset/WWW/index.html");
回答by Auri Rahimzadeh
Take a look here as well:
也看看这里:
当phonegap 版本从1.5 更新到1.9 时,android 中的Phonegap 应用程序导致强制关闭
A couple items to check:
要检查的几个项目:
- Did you copy the xmlfolder from the PhoneGap/Cordova archive to your resfolder?
- Did you copy the Cordova javascript file to your assets/wwwfolder?
- 您是否将xml文件夹从 PhoneGap/Cordova 存档复制到您的res文件夹?
- 您是否将 Cordova javascript 文件复制到您的 assets/www文件夹?
The Hello Good luck!
你好 祝你好运!
Best,
最好的事物,
-Auri
-Auri
回答by Chandan Singh
Simple answer for network error: use relative path(file:///android_asset/index.html
). make sure there is an underscore between android and asset. Eclipse creates "assets" but instead in relative path we will use android_asset.
网络错误的简单答案:使用相对路径(file:///android_asset/index.html
)。确保 android 和资产之间有一个下划线。Eclipse 创建“资产”,但在相对路径中我们将使用 android_asset。
I have wasted hours, I was using "android-asset" in the path. Also make sure you copy the xml folder from your downloaded phonegap to the res folder of your project. The xml folder contains config.xml file.
我浪费了几个小时,我在路径中使用了“android-asset”。还要确保将 xml 文件夹从下载的 phonegap 复制到项目的 res 文件夹中。xml 文件夹包含 config.xml 文件。
回答by Sharad Mhaske
// it just beacuse of connection timeout with emulator. add this line before load url.
// 这只是因为与模拟器的连接超时。在加载 url 之前添加此行。
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
回答by jinzai
...another thing that can trip you up....the cordova jar and javascript files are created when you create the project, however...on my machine they are EMPTY. I still have to manually copy them into the project folder in the appropriate spot.
...另一件事可能会让您失望....cordova jar 和 javascript 文件是在您创建项目时创建的,但是...在我的机器上它们是空的。我仍然需要手动将它们复制到适当位置的项目文件夹中。
We use Sencha Touch, so that is another part of the process where incompatibilities can creep into the project. I load a lot of Javascript from the web and the order seems relevant. I have one project that I am still wringing out, but...you can put a handler in for the WebView onReceivedError event and log the error, which sometimes helps. I also am not averse to placing alert code in the HTML file to find out where the failure occurs. We are using the webkit to serve the HTML locally on the client, too...that is another potential trouble spot.
我们使用 Sencha Touch,因此这是不兼容性可能蔓延到项目的过程的另一部分。我从网上加载了很多 Javascript 并且顺序似乎相关。我有一个项目,我仍在苦苦挣扎,但是……您可以为 WebView onReceivedError 事件放置一个处理程序并记录错误,这有时会有所帮助。我也不反对在 HTML 文件中放置警报代码以找出故障发生的位置。我们也在使用 webkit 在客户端本地提供 HTML 服务......这是另一个潜在的问题点。
回答by hannanessay
I struggled hours behind this. My Folder structure was: assets/www/index.html
我在这后面挣扎了几个小时。我的文件夹结构是:assets/www/index.html
And the code in MainActivty.java was: super.loadUrl("file:///asset/www/index.html");
MainActivty.java 中的代码是: super.loadUrl("file:///asset/www/index.html");
The Correct way is: super.loadUrl("file:///android_asset/www/index.html");
正确的方法是: super.loadUrl("file:///android_asset/www/index.html");
Its working now. Can someone explain why this "android_" is appended to the folder name?
它现在工作。有人可以解释为什么这个“android_”附加到文件夹名称?
回答by Josh
This worked for me:
这对我有用:
...I was following this tutorial: http://nick.perfectedz.com/2012/10/02/how-to-use-phonegap-with-intellijidea/#comment-286
...我正在关注本教程:http: //nick.perfectedz.com/2012/10/02/how-to-use-phonegap-with-intellijidea/#comment-286
to make a Hello World with Android IntelliJ Idea3 + Phonegap and got the same annoying error at "file:///android_asset/www/index.html"
使用 Android IntelliJ Idea3 + Phonegap 创建一个 Hello World 并在“file:///android_asset/www/index.html”中遇到同样烦人的错误
And adding this line to my Manifest.xml file solved the problem like charm:
并将这一行添加到我的 Manifest.xml 文件中解决了像魅力一样的问题:
回答by walt
<script type="text/javascript" charset="utf-8" src="cordova-1.8.1.js"></script>
Concerning the index.html:
And check if your .js-file is really named like you quoted in the src-tag.
In this case cordova-1.8.1.js
关于 index.html:
并检查您的 .js-file 是否真的像您在 src-tag 中引用的那样命名。
在这种情况下,cordova-1.8.1.js