最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Phonegap not working on android emulator(index.html not found) - Stack Overflow

programmeradmin1浏览0评论

i am using phonegap to create a native android application that displays html5 web pages and the issue is that on an emulator, the app produces a application error saying:

"the connection to the server was unsuccesfull(file://android_assets/www/index.html)"

the same app launches fine on my HTC One X so i dont think it is an issue with my code.

here is my android code

public class MainScreen extends DroidGap
{
    private Caller caller;


    private static final String Wrapper = "Wrapper";


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        caller = new Caller(this,appView);
        appView.addJavascriptInterface(caller, Wrapper);
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///assets/www/index2.html");
        // Set by <content src="index.html" /> in config.xml







public class Caller {

    private Wrapper mwrapper;
    private String serverDomain;
    private String serverFromIp;
    private String serverToIp;
    private String username;
    private String password;
    private WebView mWebView;
    private DroidGap mGap;

    public Caller(DroidGap gap, WebView webview){
        mGap = gap;
        mWebView = webview;
        mwrapper = new Wrapper();

        //TODO: figure out a way to handle callback

    }
    @JavascriptInterface
    public int register(){

    }
    @JavascriptInterface
    public void send(String message){

    }
        }

stacktrace

05-31 09:27:09.690: E/CordovaWebView(1642): CordovaWebView: TIMEOUT ERROR!
05-31 09:27:09.690: D/Cordova(1642): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
05-31 09:27:09.700: D/DroidGap(1642): onMessage(onReceivedError,{"errorCode":-6,"url":"file:\/\/\/android_asset\/www\/index.html","description":"The connection to the server was unsuccessful."})

i am using phonegap to create a native android application that displays html5 web pages and the issue is that on an emulator, the app produces a application error saying:

"the connection to the server was unsuccesfull(file://android_assets/www/index.html)"

the same app launches fine on my HTC One X so i dont think it is an issue with my code.

here is my android code

public class MainScreen extends DroidGap
{
    private Caller caller;


    private static final String Wrapper = "Wrapper";


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        caller = new Caller(this,appView);
        appView.addJavascriptInterface(caller, Wrapper);
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///assets/www/index2.html");
        // Set by <content src="index.html" /> in config.xml







public class Caller {

    private Wrapper mwrapper;
    private String serverDomain;
    private String serverFromIp;
    private String serverToIp;
    private String username;
    private String password;
    private WebView mWebView;
    private DroidGap mGap;

    public Caller(DroidGap gap, WebView webview){
        mGap = gap;
        mWebView = webview;
        mwrapper = new Wrapper();

        //TODO: figure out a way to handle callback

    }
    @JavascriptInterface
    public int register(){

    }
    @JavascriptInterface
    public void send(String message){

    }
        }

stacktrace

05-31 09:27:09.690: E/CordovaWebView(1642): CordovaWebView: TIMEOUT ERROR!
05-31 09:27:09.690: D/Cordova(1642): CordovaWebViewClient.onReceivedError: Error code=-6 Description=The connection to the server was unsuccessful. URL=file:///android_asset/www/index.html
05-31 09:27:09.700: D/DroidGap(1642): onMessage(onReceivedError,{"errorCode":-6,"url":"file:\/\/\/android_asset\/www\/index.html","description":"The connection to the server was unsuccessful."})
Share Improve this question edited May 31, 2013 at 9:02 Jono asked May 31, 2013 at 8:24 JonoJono 18.1k50 gold badges142 silver badges222 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

got it working by following this http://www.robertkehoe./2013/01/fix-for-phonegap-connection-to-server-was-unsuccessful/

发布评论

评论列表(0)

  1. 暂无评论