简体   繁体   中英

Application Error Is a directory (file:///#android_asset/www/index.html)

I'm using phonegap to develop an application on android, when I test it on my phone I get this error Application Error Is a directory (file:///#android_asset/www/index.html) I only get this error when I don't have internet connection on my phone.

any suggestions?

This means, in your index.html, you are using a resource that requires internet access. See your index.html and look for any CSS, javascript or Cordova file that is linked directly from the internet. If so, you must download the related file and make it local.

I had this same problem when I linked my Jquery mobile JS file directly like this:

<script type="CSS/javascript" src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.js">

what I did was, downloaded the jquery.mobile-1.3.0.js file and had it placed locally inside my www folder. That fixed my problem.

I found the answer here: http://dev.wavemaker.com/wiki/bin/wmdoc_6.5/PhoneGap?xpage=print#HTheconnectiontotheserverwasunsucessful28file3A2F2F2Fandroidasset2Fwww2Findexhtml29

6.1 The connection to the server was unsucessful (file:///android_asset/www/index.html)

WHERE: When launching the application on an Android device.

Anything you place within your index.html file that requests a remote resource will cause the above error to be thrown for android devices, and your application will then die. The Weinre debugger is a common cause of this error.

Solution: Move the loading of remote resources out of index.html and into your application where it will fail quietly.

you only have to rename your 'index.html' to 'main.html' for example, and create a new (dummy) 'index.html' that only have to redirect to the 'main.html'

Content of the new 'index.html':

<!doctype html>

<html>
    <head>
        <title>Title</title>
        <script>
            window.location='./main.html';
        </script>
    </head>
    <body>      
    </body>
</html>

I found the answer.

Include the phonegap.js inside your <head> tag. It is required by phonegap during build time.

<head>
<script src="phonegap.js"></script> 
</head>

You don't need to download the phonegap.js. All you just need is to include the code as shown. During build phonegap will look for it and include it automatically. If not, when you run your Native application, the application will be looking for phonegap.js on the phonegap server and this takes too long. Eventually your application load will time out with the error message you are seeing.

Wow! I can believe this. I ran into this problem and I got discouraged and almost gave up using phonegap. However, I read it in Phonegap's website about phonegap.js under the sub-heading below

https://build.phonegap.com/docs/app-overview

"Making Sure You can Still Access the PhoneGap API"

"Once you've deleted the phonegap.js you'll need to make sure that your application can still access the PhoneGap API.

To do so, simply ensure that the following reference is made in your index.html"

<script src="phonegap.js"></script>

This is like magic. It works.

Cheers everyone.

A blank access tag allows access to all external resources.

<access origin="*" /> - a wildcard access tag allows access to all external resource.

Otherwise, you can specify specific domains:

-->
    <access origin="127.0.0.1*"/> <!-- allow local pages -->
<!--
<access origin="http://phonegap.com" /> - allow any secure requests to http://honegap.com/
<access origin="http://phonegap.com" subdomains="true" /> - same as above, but including subdomains, such as http://build.phonegap.com/
<access origin="http://phonegap.com" browserOnly="true" /> - only allows http://phonegap.com to be opened by the child browser.
-->

Hope this helps.

I follow the " quick started guie " and I have the same problem. But I resolved it. My problem was a discordance between the downloaded phonegap and the guie followed.

You must be sure this details: - Into intex.html you link correct js script version (for example: cordova-2.7.0.js) - It must matchs downloaded phonegab version. phonegab version and js script linked must match.

I hope this help you.

Make sure you had included phonegap.js or cordova.js script in your page. This will work only on your mobile device.

You should use:

file:///android_asset/www/index.html

as the URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM