【问题标题】:Exception attempt to invoke virtual method - WebView Android异常尝试调用虚拟方法 - WebView Android
【发布时间】:2015-05-28 01:11:45
【问题描述】:

我在 Android 中遇到了 webview 问题

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
       super.onCreate(savedInstanceState);
       btn = (Button)findViewById(R.id.btnEn);
       wv = (WebView) findViewById(R.id.mywv);
       //webView.getSettings().setJavaScriptEnabled(true);
       //webView.loadUrl("https://mobile.twitter.com/SelbyHigh");
       ------<Error occuring here under this line>------
       wv.getSettings().setJavaScriptEnabled(true);  
       wv.getSettings().setSupportZoom(true);        
       wv.getSettings().setBuiltInZoomControls(true); 
       wv.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
       String content = "https://mobile.twitter.com/SelbyHigh";
       wv.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
       wv.loadUrl(content);
       btn.setOnClickListener(this);
    }

这里是异常的快照。当我调用它时,我的活动没有运行。 [图片链接]http://s13.postimg.org/pjlwlsnuv/errorpng.png 据我所知,当它试图达到 getsettings() 函数时,错误发生在某处。如果您有答案,请在此下方发布。如果您希望我提供更多详细信息,请对此问题发表评论。谢谢。

【问题讨论】:

  • 您的 webview 对象为空。请检查 webview id 的布局 xml!
  • 好的!我将添加一个答案使其被接受

标签: android xml exception webview error-handling


【解决方案1】:

您的 webview 对象为空。请检查 webview id 的布局 xml!

【讨论】:

    【解决方案2】:

    您的 webview 为空,因为您尚未调用 setContentView()

    在拨打任何findViewById() 电话之前,请先拨打setContentView()

    【讨论】:

    • 感谢您提供更好的解释。
    猜你喜欢
    • 1970-01-01
    • 2017-07-24
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2015-06-21
    • 2018-08-11
    相关资源
    最近更新 更多