Android浏览器无法打开网页

时间:2013-05-21 12:47:31

标签: android android-webview android-internet

您好我是Android的新手,我为“简单的网络浏览器”编写了一个小应用程序。 但是我的浏览器无法打开页面,并且显示错误,例如没有网络可用(网页不可用),即使wifi已开启且普通浏览器正在该设备上运行。

请检查以下代码:: 的 SimpleBrowser.java

package com.thenewboston.travis;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

public class SimpleBrowser extends Activity implements OnClickListener{

    Button bGo,bBack,bForward,bHistory,bRefresh;
    EditText et;
    WebView wb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simplebrowser);

        bGo = (Button)findViewById(R.id.go);
        bBack = (Button)findViewById(R.id.bBack);
        bForward = (Button)findViewById(R.id.bForward);
        bHistory = (Button)findViewById(R.id.bHistory);
        bRefresh = (Button)findViewById(R.id.bRefresh);
        et = (EditText)findViewById(R.id.editAddress);
        wb = (WebView)findViewById(R.id.webView);
        wb.setWebViewClient(new ourViewClient());

        bGo.setOnClickListener(this);
        bBack.setOnClickListener(this);
        bForward.setOnClickListener(this);
        bHistory.setOnClickListener(this);
        bRefresh.setOnClickListener(this);

        //wb.loadUrl("http://www.gmail.com");





    }
    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getId())
        {
        case R.id.go:
            String website = et.getText().toString();
            wb.loadUrl(website);            
            break;
        case R.id.bBack:
            if(wb.canGoBack())
            wb.goBack();

            break;
        case R.id.bForward:
            if(wb.canGoForward())
            wb.goForward();
            break;
        case R.id.bHistory:
            wb.clearHistory();

            break;
        case R.id.bRefresh:
            wb.reload();

            break;

        }

    }



}

ourViewClient.java

package com.thenewboston.travis;

import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ourViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub
        view.loadUrl(url);
        return true;
    }



}

和...... 的的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thenewboston.travis"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="KCRaju"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.thenewboston.travis.Splash"
        android:label="KCRaju"
        android:screenOrientation="portrait" >
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".StartingPoint"
        android:label="KCRaju" >
        <intent-filter>
        <action android:name="com.thenewboston.travis.STARTINGPOINT" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Menu"
        android:label="KCRaju" >
        <intent-filter>
        <action android:name="com.thenewboston.travis.MENU" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <activity
        android:name=".prefs"
        android:label="KCRaju" >
        <intent-filter>
        <action android:name="com.thenewboston.travis.prefs" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".About"
        android:label="KCRaju"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
        <action android:name="com.thenewboston.travis.About" />
        <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
    </activity>
        <activity android:name=".TextPlay" android:label="@string/app_name" >
    </activity>
        <activity android:name=".Email" android:label="@string/app_name" >
    </activity>
         <activity android:name=".Camera" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
     <activity android:name=".Data" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".GFX" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".GFXSurface" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".SoundStuff" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".Slider" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".Memory" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".OpenedClass" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".Tabs" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    <activity android:name=".SimpleBrowser" android:label="@string/app_name" android:screenOrientation="portrait" >
    </activity>
    </application>

</manifest>

2 个答案:

答案 0 :(得分:1)

我们需要为url提供 https 作为loadUrl的后缀

答案 1 :(得分:0)


在您的代码中:

wb.loadUrl(website);

你传递了什么网站。检查它是有效网站的字符串。复制字符串并粘贴在Android手机的浏览器中然后检查它是否显示