2012-05-03 32 views
2

我刚刚收到分包商的PhoneGap解决方案,以便在启动之前在我的手机上对其进行测试。使用Eclipse测试PhoneGap应用程序时,出现“发生网络错误”

我将项目导入到Eclipse中,看起来一切正常。

我可以通过打开index.html文件进行本地测试应用程序在我的电脑上:

file://E:/AppDevelopment/Workspace/myproject/assets/www/index.html 

到目前为止好。然后,我尝试启动这个我的手机(通过USB电缆)。首页打开,但CSS丢失。当我点击任何链接时,我会收到以下消息:

"A network error occurred. (file:///android_asset/www/car.html?carID=106" 

有没有人有类似的问题?任何建议如何我可以调试什么是错的?

UPDATE

继Dmyto的建议,我试图改变onReceivedError。但我只能得到编码错误。

package com.phonegap.mysite; 

import android.os.Bundle; 
import org.apache.cordova.*; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class Mysiteextends DroidGap { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     super.loadUrl("file:///android_asset/www/index.html"); 

    } 

/** This is where it goes wrong **/ 

    WebView webview = new WebView(this); 

    webview.setWebViewClient(new WebViewClient() { 
     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
       Log.i("WEB_VIEW_TEST", "error code:" + errorCode); 
       super.onReceivedError(view, errorCode, description, failingUrl); 
     } 

} 

回答

2

没有看到您的index.html代码,很难判断您是否正确引用了您的css文件。此外,该网址:file:///android_asset/www/car.html=carID=106似乎不正确? =carID=106是什么?正确的URL应该是?carID=106。但等一下,还有一个Android的错误,其中URL参数不能正确读取。

这是Android上的一个错误。你应该去星吧:

https://code.google.com/p/android/issues/detail?id=17535 

同时使用localStorage.setItem()/getItem()在网页之间传送值。

+0

对不起,该网址是一个错字。我使用'?'而不是'='。正确的URL是'file:///android_asset/www/car.html?carID = 106'。正如我在Q中所述,当我在我的电脑(和Eclipse)上测试时,该应用程序工作正常,而不是在我的手机上。我没有编码Android应用程序的经验,所以**在各种代码的**处都非常空白。 – Steven

+1

正确的是,你正在被Android操作系统中的错误绊倒。所以如果你想将信息从一个页面传递到另一个页面,你需要使用localStorage。 –

+0

经过一番测试,你是绝对正确的。我的问题是;是否将使用localStorage适用于iOS和Windows手机? – Steven

0

您可以设置WebViewClient到您的网络视图,ovveride onReceivedError方法。

+0

我从来没有编码的一条线的应用程序(恩切分包商)。我在什么文件中设置WebViewClient? – Steven

+0

请参阅文档:http://developer.android.com/reference/android/webkit/WebView.html –

+0

是的,我看到它,但它没有说明在哪里。我应该把它放在每个我想测试的* .html文件上吗?或者应该把它放在一些js脚本中? **编辑:**我想我在这里找到答案:http://developer.android.com/resources/tutorials/views/hello-webview.html – Steven

0

您可能需要使用IceCreamCordovaWebViewClient

@Override 
    public void init() { 
    super.init(webView, new IceCreamCordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView)); 
} 
相关问题