简体   繁体   English

应用程序错误:出现网络错误(文件:///assets/www/index.html

[英]Application error: there was a network error(file:///assets/www/index.html

I am trying to run a phonegap application on eclipse juno. 我试图在Eclipse Juno上运行phonegap应用程序。 The android version is 4.1.2. android版本是4.1.2。 The application gives an error saying: 应用程序给出错误提示:

Application error: there was a network error(file:///assets/www/index.html when i try to run the app. 应用程序错误:出现网络错误(当我尝试运行该应用程序时,文件:///assets/www/index.html。

The android manifest is as follows android清单如下

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
      package="com.initial.belgium" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
        />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />   
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.BROADCAST_STICKY" />


    <application android:icon="@drawable/icon" android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:debuggable="true">
        <activity android:name="belgium" android:label="@string/app_name"
                android:theme="@android:style/Theme.Black.NoTitleBar"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16"/>
</manifest> 

The java source is as follows: Java来源如下:

package com.initial.belgium;

import android.os.Bundle;
import org.apache.cordova.*;

public class belgium extends DroidGap
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.loadUrl("file:///assets/www/index.html"); 
    }
}

Could someone help me fix this?? 有人可以帮我解决这个问题吗? Thanks 谢谢

Try changing: 尝试更改:

super.loadUrl("file:///assets/www/index.html");

To: 至:

super.loadUrl("file:///android_asset/www/index.html");

For me the issue was that the Phonegap "Hello World" tutorial for Android simply does not work. 对我来说,问题是Android的Phonegap“ Hello World”教程根本无法正常工作。 It created a sub-folder under platforms / android / assets called "phonegap-app-hello-world-3.1.0". 它在平台/ android /资产下创建了一个名为“ phonegap-app-hello-world-3.1.0”的子文件夹。 This folder is where all the files were, so once I changed the loadUrl parameter to reflect that it loaded without the error: 该文件夹是所有文件的存放位置,因此一旦更改了loadUrl参数以反映它已加载且没有错误:

super.loadUrl("file:///android_asset/www/phonegap-app-hello-world-3.1.0/www/index.html");

Hope this helps someone, would have saved me a couple of hours of mucking around! 希望这对某人有帮助,可以节省我几个小时的时间!

I found a really good solution to this online. 我在网上找到了一个非常好的解决方案。

What you basically need to do is to move the contents of index.html to another file, say app.html. 您基本上需要做的是将index.html的内容移动到另一个文件,例如app.html。

Then have the following code in your original index.html: 然后在原始index.html中添加以下代码:

<!doctype html>
<html>
   <head>
       <title>tittle</title>
   </head>
   <body>
       <script>
           window.location='./app.html';
       </script>
   </body>
</html>

The connection to the server won't timeout anymore and the app should load successfully. 与服务器的连接不会再超时,应用程序应成功加载。

Now I didn't come up with this great idea. 现在,我没有想到这个好主意。 All credit goes to Robert Kehoe: 所有的功劳归功于Robert Kehoe:

https://www.robertkehoe.com/2013/01/fix-for-phonegap-connection-to-server-was-unsuccessful/ https://www.robertkehoe.com/2013/01/fix-for-phonegap-connection-to-server-was-unsuccessful/

Doing this helped me solve a similar problem with my own Android phonegap application... 这样做有助于我使用自己的Android phonegap应用程序解决类似的问题...

.loadUrl should take a url that is pointing to a server. .loadUrl应该使用指向服务器的URL。 Change it to http://www.google.com/ and it should work. 将其更改为http://www.google.com/ ,即可正常运行。

To use your own files, upload them to a web server or start one on your local machine. 要使用自己的文件,请将其上传到Web服务器或在本地计算机上启动一个。 If you are on a mac, there is one built-in (simply enable Web Sharing from System Setting). 如果您使用的是Mac,则内置一个(只需从“系统设置”中启用“ Web共享”)。 Or if you have Python installed, you can run python -m SimpleHTTPServer from the /assets/www directory, and then change the URL to 'http://localhost:8000/index.html' 或者,如果您安装了Python,则可以从/assets/www目录运行python -m SimpleHTTPServer ,然后将URL更改为'http://localhost:8000/index.html'

For me, this problem was caused by the fact that I edited and renamed both an index.html file and an app.js file. 对我来说,此问题是由于我编辑并重命名了index.html文件和app.js文件而引起的。 When I renamed I included the extension .html and .js. 当我重命名时,我包括扩展名.html和.js。 This caused the files to be renamed to index.html.html and app.js.js. 这导致文件被重命名为index.html.html和app.js.js。 So clearly the project could not find the files it was looking for. 因此很明显,该项目找不到所需的文件。 I believe this is a manifestation of the answers given above. 我相信这是上述答案的体现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 phonegap Hello World示例-无法调用未定义的方法“ getPicture””,来源:file:///android_asset/www/index.html - phonegap Hello World Example - Cannot call method 'getPicture' of undefined", source: file:///android_asset/www/index.html Spring Boot / Eclipse index.html:发生意外错误(类型=未找到,状态= 404) - Spring Boot/Eclipse index.html: There was an unexpected error (type=Not Found, status=404) 调用默认的jsp页面时出现404错误,能够调用index.html - 404 error when called the default jsp page, able to call index.html 动态Web应用程序所请求的资源(/helloWorld/index.html)不可用 - Dynamic Web Application The requested resource (/helloWorld/index.html) is not available “初始化网络连接时出错:找不到类”,来源:file:///android_asset/www/cordova.js - “Error initializing Network Connection: Class not found”, source: file:///android_asset/www/cordova.js Libgdx GWT war文件夹中没有index.html文件 - Libgdx GWT No index.html file in war folder Cucumber 未在目标文件夹中生成 index.html 文件 - Cucumber is not generating index.html file in the target folder 生成的javadoc但index.html很奇怪 - Generated javadoc but index.html gone weird 如何在该本地主机中打开资源:8080 / test / index.html? - How to open my resource in that localhost:8080/test/index.html? HTTP状态404-请求的资源(/BookStore/index.html)不可用 - HTTP Status 404 - The requested resource (/BookStore/index.html) is not available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM