0

I am learning to develop web app with jquerymobile and Android sdk. My web app is structured in some pages that are loaded with:

private void loadURL(final String in){
    handler.post(new Runnable() {
        public void run() {
            webView.loadUrl(in);
        }
    });
}

public void loadPage(String in){
    final String url = HTML_ROOT + in;
    loadURL(url);
}

This is my onCreate method:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    webView = new WebView(this); //super.init();

    setContentView(webView);
    webView.getSettings().setJavaScriptEnabled(true);   

    .....

    handler = new Handler();
    webView.addJavascriptInterface(this, "MyTeam");       
    loadPage("menu.html");

}

And onkeydown method:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if(webView == null){
          Log.d("My Tag", "Webview is null on KeyCode: " + String.valueOf(keyCode));
        }
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
}

The problem is: example a: 1- from menu.html I go in another page xxx.html 2- I click back button on my smartphone 3- onKeyDown is fired

example b: 1- from menu.html I click on smartphone backbutton or another button

After return super.onkeydown I have returned in example a and example b:

12-01 15:34:56.796: E/AndroidRuntime(14048): FATAL EXCEPTION: main
12-01 15:34:56.796: E/AndroidRuntime(14048): java.lang.NullPointerException
12-01 15:34:56.796: E/AndroidRuntime(14048):    at org.apache.cordova.DroidGap.onKeyUp(DroidGap.java:1018)

Why DroidGapClass return me null pointer exception?????

Thanks a lot.

michele
  • 26,348
  • 30
  • 111
  • 168
  • r u solved this problem? – Jackson Chengalai Jan 17 '13 at 06:41
  • You've kinda gone off script here with PhoneGap since you are a) providing your own JS interface, b) providing your own loadUrl method and c) overriding the back button behaviour. If I understood why you are doing abc it would be easier to help. At a minimum you should use the plugin API and not addJavascriptInterface. – Simon MacDonald Feb 22 '13 at 19:29

0 Answers0