2013-07-02 2 views
-1

J'ai créé une application Webview. mais ça ne marche pas. Il est coincé quand je le tester sur un appareil AndroidMon application Webview ne s'ouvre pas

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/"); 



    } 


} 

de 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> 

Qui peut me aider?

Thanx

+2

initialise la vue Web. – TheFlash

Répondre

1

Vous n'avez une WebView là-dedans du tout. Changer votre mise en page:

<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> 

Puis dans votre activité faire:

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

    webView = (WebView) findViewById(R.id.webView); 
    webView.loadUrl("http://m.neshaniha.org/"); 
} 

Assurez-vous également que cela est dans votre manifest.xml

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

Vous n'avez pas initialisé la vue Web.

Comme ceci:

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"); 
0

Ajouter webView en XML comme ci-dessous:

<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> 

S'il vous plaît ini tialize WebView comme ci-dessous:

WebView webView = (WebView)findViewById(R.id.webView); 
webView.setWebViewClient(new WebViewClient()); 
webView.loadUrl("http://m.neshaniha.org/"); 
0

d'abord aller comme ça:

WebView myWebView = (WebView) findViewById(R.id.webview); 

Vous devez définir la @+id de votre WebView, comme ça:

<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/webview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
/> 
0

Dans votre code java, vous a déclaré votre WebView en tant que variable membre, mais vous ne l'initialisez à rien. Par conséquent, lorsque vous essayez d'ouvrir l'URL, vous obtenez un NullPointerException. Il y a deux problèmes avec votre code.

D'abord, vous devez ajouter le WebView à votre disposition:

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

Puis dans votre code java vous devez trouver ce WebView et l'assigner à votre variable avant de charger l'url:

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

    webView = (WebView)findViewById(R.id.webview); 
    webView.loadUrl("http://m.neshaniha.org/"); 
} 
Questions connexes