android – 使用ActionBarCompat的ProgressBar的NullPointerException

前端之家收集整理的这篇文章主要介绍了android – 使用ActionBarCompat的ProgressBar的NullPointerException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在support-v7-r18中使用ActionBarCompat. @H_502_2@当试图显示不确定的进度时,它适用于Galaxy S3 Android 4.1.2,但不适用于Galaxy Ace Android 2.3.3.

我无法理解为什么.

提出异常的代码

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    final ActionBarActivity activity = this;
    content = (WebView) findViewById(R.id.webContent);
    content.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view,String url,Bitmap favicon) {
            super.onPageStarted(view,url,favicon);
            activity.setSupportProgressBarIndeterminate(true);   <=== Line 88
            activity.setSupportProgressBarIndeterminateVisibility(true);
        }
    }

例外:

FATAL EXCEPTION: main
    java.lang.NullPointerException
    at  android.support.v7.app.ActionBarActivityDelegateBase.updateProgressBars(ActionBarActivityDelegateBase.java:508)
    at android.support.v7.app.ActionBarActivityDelegateBase.setSupportProgressBarIndeterminate(ActionBarActivityDelegateBase.java:469)
    at android.support.v7.app.ActionBarActivity.setSupportProgressBarIndeterminate(ActionBarActivity.java:282)
    at MyActivity.onPageStarted(MyActivityActivity.java:88)
    at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:266)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)

解决方法

添加supportRequestWindowFeature(Window.FEATURE_PROGRESS);或supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);调用setContentView()之前的onCreate()方法.

猜你在找的Android相关文章