Keep getting “A network error occurred” when testing PhoneGap app with Eclipse

匿名 (未验证) 提交于 2019-12-03 02:22:01

问题:

I've just received the PhoneGap solution from by sub-contractor in order to test it on my phone before launch.

I import the project into Eclipse and it all looks fine.

I can test the app locally on my computer by opening the index.html file:

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

So far so good. Then I try launching this an my phone ( via USB cabel). The front page opens, but the CSS is missing. And when I click any link, I get the following message:

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

Has anyone had similar problems? Any suggestions to how I can debug what is wrong?

UPDATE

Following Dmyto's suggestion, I'm trying to change the onReceivedError. But I only get coding errirs.

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);         }  } 

回答1:

Without seeing your index.html code it is hard to tell if you are referencing your css files properly. Also, that url: file:///android_asset/www/car.html=carID=106 doesn't seem valid? What is with the =carID=106? A proper URL should be ?carID=106. But wait there's more, there is a bug on Android where url paramters are not read properly.

It's a bug on Android. You should go star it:

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

In the meantime use localStorage.setItem()/getItem() to pass values between pages.



回答2:

You can set WebViewClient to your web view, and ovveride onReceivedError method.



回答3:

You might need to use IceCreamCordovaWebViewClient

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!