簡體   English   中英

android webview導致空指針

[英]android webview causing null pointer

我的布局中有這個:

<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所以不知道我在做什么!

添加setContentView(R.layout.your_layout);

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM