本文介绍了NullPointerException异常使用ActionBarCompat进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我支持-V7-R18使用ActionBarCompat。当试图显示一个不确定的进度,它适用于银河S3的Andr​​oid 4.1.2,但不会对银河王牌的Andr​​oid 2.3.3。

我不明白为什么。

在code提高了异常:

  @覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    ...
    最后ActionBarActivity活性=这一点;
    内容=(web视图)findViewById(R.id.webContent);
    content.setWebViewClient(新WebViewClient(){
        @覆盖
        公共无效onPageStarted(web视图查看,字符串URL,位图图标){
            super.onPageStarted(查看,网址,网站图标);
            activity.setSupportProgressBarIndeterminate(真正的); < === 88号线
            activity.setSupportProgressBarIndeterminateVisibility(真正的);
        }
    }
 

例外情况:

 致命异常:主要
    显示java.lang.NullPointerException
    在android.support.v7.app.ActionBarActivityDelegateBase.updateProgressBars(ActionBarActivityDelegateBase.java:508)
    在android.support.v7.app.ActionBarActivityDelegateBase.setSupportProgressBarIndeterminate(ActionBarActivityDelegateBase.java:469)
    在android.support.v7.app.ActionBarActivity.setSupportProgressBarIndeterminate(ActionBarActivity.java:282)
    在MyActivity.onPageStarted(MyActivityActivity.java:88)
    在android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:266)
    在android.os.Handler.dispatchMessage(Handler.java:99)
    在android.os.Looper.loop(Looper.java:123)
    在android.app.ActivityThread.main(ActivityThread.java:3687)
    在java.lang.reflect.Method.invokeNative(本机方法)
    在java.lang.reflect.Method.invoke(Method.java:507)
    在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)
    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    在dalvik.system.NativeStart.main(本机方法)
 

解决方案

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

I'm using ActionBarCompat in support-v7-r18.When trying to show an indeterminate progress, it works on Galaxy S3 Android 4.1.2 but doesn't on Galaxy Ace Android 2.3.3.

I can't figure why.

The code raising the exception :

@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);
        }
    }

The exception :

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)
解决方案

Add supportRequestWindowFeature(Window.FEATURE_PROGRESS);or supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); to onCreate() method before calling setContentView().

这篇关于NullPointerException异常使用ActionBarCompat进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:25