【问题标题】:Progress Bar Error at runtime运行时进度条错误
【发布时间】:2010-12-02 06:36:31
【问题描述】:

当我尝试在手机上运行该程序时,它不断崩溃。不知道为什么会崩溃

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

【问题讨论】:

    标签: android progress-bar android-webview


    【解决方案1】:

    你会想从崩溃中找到堆栈跟踪,你可以用 logcat 得到它,或者在 eclipse 中打开 logcat 视图(或打开 DDMS 透视图),或者从 shell 运行 adb logcat 来查看日志。

    不过,在这种情况下,我很确定您会看到任何错误提示您需要在创建任何内容之前设置窗口功能,请将您的 setContentView 呼叫移至 getWindow().requestFeature 呼叫之后。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-01
      • 2017-02-23
      • 2012-12-30
      • 1970-01-01
      相关资源
      最近更新 更多