Android进度条出现异常

Android进度条出现异常,android,android-webview,android-progressbar,Android,Android Webview,Android Progressbar,我正在Android中使用web view,并尝试添加进度条,以下是我的代码: case R.id.studentsite: getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.webview); WebView wv1 = (WebView)findViewById(R.id.webview); W

我正在Android中使用web view,并尝试添加进度条,以下是我的代码:

case R.id.studentsite:
            getWindow().requestFeature(Window.FEATURE_PROGRESS);
            setContentView(R.layout.webview);
            WebView wv1 = (WebView)findViewById(R.id.webview);
            WebSettings ws1 = wv1.getSettings();
            final Activity activity = this;
            wv1.setWebChromeClient(new WebChromeClient() {
              public void onProgressChanged(WebView view, int progress) {
                // Activities and WebViews measure progress with different scales.
                // The progress meter will automatically disappear when we reach 100%
                activity.setProgress(progress * 1000);
              }
            });
            wv1.setWebViewClient(new WebViewClient() {
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
              }
            });
            wv1.getSettings().setBuiltInZoomControls(true);
            ws1.setJavaScriptEnabled(true);
            wv1.setWebViewClient(new WebViewClient());
            wv1.loadUrl("http://www.studentsite.gunadarma.ac.id");
            break;
问题是我在LOGCAT上遇到了如下异常:

09-17 13:51:34.487:错误/AndroidRuntime(1331):致命异常:main
09-17 13:51:34.487:错误/AndroidRuntime(1331):添加内容之前必须调用android.util.AndroidRuntimeException:requestFeature()
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:181)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于com.ugsimplify.ugweb.callintent(ugweb.java:89)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于com.ugsimplify.ugweb$1.onClick(ugweb.java:29)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.view.view.performClick(view.java:2485)上
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.widget.CompoundButton.performClick(CompoundButton.java:99)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.view.view$PerformClick.run(view.java:9080)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.os.Handler.handleCallback(Handler.java:587)上
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.os.Handler.dispatchMessage(Handler.java:92)上
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在android.os.Looper.loop(Looper.java:123)上
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于android.app.ActivityThread.main(ActivityThread.java:3647)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于java.lang.reflect.Method.invokenactive(本机方法)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于java.lang.reflect.Method.invoke(Method.java:507)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-17 13:51:34.487:ERROR/AndroidRuntime(1331):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-17 13:51:34.487:错误/AndroidRuntime(1331):在dalvik.system.NativeStart.main(本机方法)


你知道怎么修吗?谢谢。

super.Oncreate

    Hi Here is problem that you have call.


  getWindow().requestFeature(Window.FEATURE_PROGRESS); before  setContentView(R.layout.webview);
    It should be call below the setContentView(R.layout.webview);

    Answer :-


                setContentView(R.layout.webview);
    getWindow().requestFeature(Window.FEATURE_PROGRESS);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
您正在调用Button click,您已经为其设置了内容。
只能在首次设置contentView之前请求进度条功能。

根据日志,您在设置contentView之后使用了requestFeature

您发布的代码部分非常完美


我怀疑您已经在其他地方使用过setContentView,可能是在onCreate方法中。

activity.setProgress是否正确?它应该是正确的,但它没有显示任何进度条,您想帮忙吗?您可能会在这里得到答案:谢谢您解决了我的问题,但您能告诉我为什么我没有看到任何关于进度条的内容吗,它不会显示任何内容。它将显示在标题栏上。活动进度条的值从0到10000,所以我想您必须乘以100,而不是1000。