Android 我的webview应用程序没有';t打开

Android 我的webview应用程序没有';t打开,android,eclipse,Android,Eclipse,我制作了一个webview应用程序。但它不起作用。 当我在安卓设备上测试时,他被卡住了 FullscreenActivity.java package com.solidos.neshaniha; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class FullscreenActivity extends Activity { private

我制作了一个webview应用程序。但它不起作用。 当我在安卓设备上测试时,他被卡住了

FullscreenActivity.java

package com.solidos.neshaniha;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class FullscreenActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        webView.loadUrl("http://www.mywebsite.nl/");



    }


}
activity_fullscreen.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="#0099cc"
 tools:context=".FullscreenActivity" >

 </FrameLayout>

谁能帮我


Thanx

您没有初始化webview

像这样:

private WebView webView;

webview = (Webview)findViewById(R.id.webview1);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webview.loadURL("nananan");

你根本没有网络视图。将布局更改为:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context=".FullscreenActivity" >

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>
还要确保这是在您的
manifest.xml

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

在xml中添加webView,如下所示:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity" >

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</FrameLayout>
WebView webView = (WebView)findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://m.neshaniha.org/");
首先,这样做:

WebView myWebView = (WebView) findViewById(R.id.webview);
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
您应该定义
WebView
@+id
,如下所示:

WebView myWebView = (WebView) findViewById(R.id.webview);
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

在java代码中,您将WebView声明为一个成员变量,但并没有初始化它。因此,当您尝试在其中打开URL时,您会得到一个
NullPointerException
。您的代码有两个问题

首先,您需要将WebView添加到布局中:

<FrameLayout ...>
    <WebView android:id="@+id/webview" ... />
</FrameLayout>

初始化web视图。