首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

关于android调用浏览器有关问题,请各位大侠给予指点,程序贴出,候

2013-04-20 
关于android调用浏览器问题,请各位大侠给予指点,程序贴出,在线等候!出现的问题是,在没加上MyWebViewClient

关于android调用浏览器问题,请各位大侠给予指点,程序贴出,在线等候!
出现的问题是,在没加上
MyWebViewClient myWebView=new MyWebViewClient();  
webview.setWebViewClient(myWebView); 
这两段程序,是好用的,能够调出给出的url,但是加上上面的那两段程序后,就报错,报的错误是“the application has stopped unexpectedly”,android程序开发新手,请各位大侠给予指点,多谢多谢了!
具体的程序代码如下,在线等候!
 
activity程序:

public class MainActivity extends Activity {
 private WebView mWebView; 
 private ProgressDialog dialog;  
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.mainoa);
 WebSettings webSettings = mWebView.getSettings();       
        webSettings.setJavaScriptEnabled(true); 
        webSettings.setPluginsEnabled(true); 
        mWebView.requestFocus();
        //取消滚动条
        //this.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
        mWebView.loadUrl("http://www.baidu.com/");
        MyWebViewClient myWebView=new MyWebViewClient(); 
        mWebView.setWebViewClient(myWebView);

}

    @Override//设置回退  
    public boolean onKeyDown(int keyCode, KeyEvent event) {  
        if((keyCode==KeyEvent.KEYCODE_BACK) || mWebView.canGoBack()){  
        mWebView.goBack();  
            return true;  
        }  
        return super.onKeyDown(keyCode, event);  
    }  
    @Override  
    protected Dialog onCreateDialog(int id) {  
        //实例化进度条对话框  
        dialog=new ProgressDialog(this);  
        /*//可以不显示标题 
        dialog.setTitle("正在加载,请稍候!");*/  
        dialog.setIndeterminate(true);  
        dialog.setMessage("正在加载,请稍候!");  
        dialog.setCancelable(true);  
        return dialog;  
    }  


    private class MyWebViewClient extends WebViewClient{  
        @Override  
        public boolean shouldOverrideUrlLoading(WebView view, String url) {  
            view.loadUrl(url);  
            return true;  
        }  
        


    /*
     * 在加载页面 结束时响应
     */
        @Override 
        public void onPageFinished(WebView view, String url) {  
            dialog.dismiss();  
        }  
        
        /*
         * 在加载出错时响应
         */
        @Override 
        public void onReceivedError(WebView view, int errorCode,  
                String description, String failingUrl) {  
            // TODO Auto-generated method stub  
            super.onReceivedError(view, errorCode, description, failingUrl);  
            dialog.dismiss();  
        }  
    }

}

lay_out程序
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainoa"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    

</WebView>


manifest.xml程序
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.zloa"
    android:versionCode="1"
    android:versionName="1.0" >
    
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.zloa.MainActivity"
            android:label="@string/title_activity_oa_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>
    </application>

</manifest>
[解决办法]
  MyWebViewClient myWebView=new MyWebViewClient(); 

这句改成WebViewClient myWebView=new WebViewClient(); 试试

热点排行