2012-02-29 15 views
0

私はアンドロイドで働いています。私はwebviewを使ってウェブページを表示したい。しかし、私は違った方法でページを表示したいので、最初にそのWebページのHTMLを取得しようとしましたが、そのHTMLコードをWebページとして表示しようとしました。 ウェブビュー:ウェブページは利用できません

この

これはアクティビティコードである私のmain.xml

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

です: -

public class MyWebViewActivity extends Activity { 
WebView mWebView; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mWebView = (WebView) findViewById(R.id.webview); 
    mWebView.getSettings().setJavaScriptEnabled(true); 


    String resString = "<html><body><h1>Hello, Quippelin...</h1></body></html>"; 
    try { 
     HttpClient httpclient = new DefaultHttpClient(); 

     HttpGet httpget = new HttpGet("http://google.com"); 

     HttpResponse response = httpclient.execute(httpget); 
     HttpEntity entity = response.getEntity(); 
     InputStream is = entity.getContent(); 

     BufferedReader reader = new BufferedReader(new InputStreamReader(
       is, "iso-8859-1"), 8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while ((line = reader.readLine()) != null) 

      sb.append(line + "\n"); 

     resString = sb.toString(); 

     is.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    mWebView.loadData(resString, "text/html", "UTF-8"); 
} 

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { 
     mWebView.goBack(); 
     return true; 
    } 
    return super.onKeyDown(keyCode, event); 
} 

}

しかし、私はこのエラーが発生しているこのアプリケーションを実行するたびに: - enter image description here

私に間違いがあることを教えてください完了しました。私は本当に助けが必要です。 ありがとうございます。

答えて

0

使用この..

 Uri uri = Uri.parse("http://www.google.com "); 
    Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
    startActivity(intent); 
+0

Nitesh先生私はあなたのことを何でもよく熟知しています。私の質問について考えてください。私は別の方法でこの事をしたい、それは私のアプリケーションの第一歩です。私はWebページのHTMLを解析したい。 –

関連する問題