Android Webview崩溃了应用程序

时间:2015-06-17 06:04:09

标签: java android webview

在我的应用中实施了webview。但是在调试时,它会崩溃。

这是我的MakePaymentActivity.java

public class MakePaymentActivity extends BaseActivity {

    public static String bookingId, userId, refId, Url;
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_make_payment);
        webView = (WebView) findViewById(R.id.webview);

        Url = URLConstants.MAKE_PAYMENT+"?user_id="+userId+"&ref_id="+refId+"&book_id="+bookingId;
        startWebView(Url);
    }

    private void startWebView(String url) {

        //Create new webview Client to show progress dialog
        //When opening a url or click on link

        webView.setWebViewClient(new WebViewClient() {      
            ProgressDialog progressDialog;

            //If you will not use this method url links are opeen in new brower not in webview
            public boolean shouldOverrideUrlLoading(WebView view, String url) {              
                view.loadUrl(url);
                return true;
            }

            //Show loader on url load
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                    // in standard case YourActivity.this
                    progressDialog = new ProgressDialog(MakePaymentActivity.this);
                    progressDialog.setMessage("Loading...");
                    progressDialog.show();
                }
            }
            public void onPageFinished(WebView view, String url) {
                try{
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
                }catch(Exception exception){
                    exception.printStackTrace();
                }
            }

        }); 

         // Javascript inabled on webview  
        webView.getSettings().setJavaScriptEnabled(true); 

        //Load url in webview
        webView.loadUrl(url);


    }

}

XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:id="@+id/webview">
 </WebView>

请帮忙解决这个问题。 提前致谢

1 个答案:

答案 0 :(得分:0)

对不起。我是Android的新手。我发现了这个问题。我只是忘了在AndroidManifest.xml中声明活动