【问题标题】:android webview causing null pointerandroid webview导致空指针
【发布时间】:2012-11-24 12:10:28
【问题描述】:

我的布局中有这个:

<WebView 
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

这在我的活动中:

public class Shop extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    WebView webview;
    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.example.co.uk/shop");
}
}

清单中的这个:

<uses-permission android:name="android.permission.INTERNET" />

然而,当我运行应用程序时,我收到一个强制关闭错误,并且日志中有一个空指针。我以前从未使用过 webview,所以不知道我在做什么!

【问题讨论】:

  • 请在您的问题中添加 logcat 消息
  • com.example.chobbyblings.Shop.onCreate(Shop.java:15) -error

标签: java android webview nullpointerexception


【解决方案1】:

添加setContentView(R.layout.your_layout);:

super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);

【讨论】:

  • 这太明显了……谢谢!抱歉,我可能应该知道!
猜你喜欢
  • 2015-09-12
  • 1970-01-01
  • 1970-01-01
  • 2014-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-02
  • 1970-01-01
相关资源
最近更新 更多