0
我的webview
模塊不工作。每當我嘗試從任何網頁導航,應用程序崩潰給出以下錯誤Android WebView停止點擊返回
"Unfortunately the app has stopped".
任何人都可以請解釋是什麼原因?
public class MainActivity extends ActionBarActivity {
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("http://nahdaschools.com/v4/index.php/apps");
}
private class MyCustomWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed() {
if (myWebView.copyBackForwardList().getCurrentIndex() > 0) {
myWebView.goBack();
}
else {
// Your exit alert code, or alternatively line below to finish
super.onBackPressed(); // finishes activity
}
}}
夥計那裏是我的堆棧跟蹤! – goonerDroid
@goonerDroid [here](https://politecuriosity.files.wordpress.com/2013/05/logcat.jpg):D – Gattsu
你能告訴我們你的堆棧跟蹤嗎?也許copyBackForwardList()返回null,你試圖獲取空對象上的當前索引? – yrazlik