0

ハンドセットでプログラムを実行しようとすると、プログラムがクラッシュし続けます。クラッシュする理由がわかりません

メイン Java

public class ProgressBar extends Activity {

WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main );
 final Activity MyActivity = this;

// Makes Progress bar Visible
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

webview = (WebView) findViewById(R.id.webview);
webview.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress)   
    {
     //Make the bar disappear after URL is loaded, and changes string to Loading...
    MyActivity.setTitle("Loading...");
     MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded

     // Return the app name after finish loading
        if(progress == 100)
           MyActivity.setTitle(R.string.app_name);
      }
    });

webview = (WebView) findViewById(R.id.webview);
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com/");

}
private class HelloWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.loadUrl(url);
    return true;
    }
    }
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
    webview.goBack();
    return true;
    }
    return super.onKeyDown(keyCode, event);
    }
    }

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>
4

1 に答える 1

2

クラッシュからスタック トレースを見つける必要があります。これは、logcat で取得できます。Eclipse で logcat ビューを開く (または DDMS パースペクティブを開く) かadb logcat、シェルから実行してログを表示します。

setContentViewただし、この場合、コンテンツを作成する前にウィンドウ機能を設定する必要があるというエラーが表示され、呼び出しの後に呼び出しを移動する必要があると確信していgetWindow().requestFeatureます。

于 2010-12-02T06:41:45.500 に答える