可能是numberpicker nullpointer(使用Tourguide)的原因是什么?

时间:2016-03-08 02:16:56

标签: android viewgroup

所以我有一个数字选择器和一个日期选择器,除了我的观点与旅游指南库https://github.com/worker8/TourGuide相关联时,每个人都在工作,

FATAL EXCEPTION: main
java.lang.NullPointerException
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2988)
        at android.view.View.getDisplayList(View.java:12428)
        at android.view.View.getDisplayList(View.java:12545)
        at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1184)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:2446)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2306)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2109)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1127)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4606)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:747)
        at android.view.Choreographer.doCallbacks(Choreographer.java:567)
        at android.view.Choreographer.doFrame(Choreographer.java:536)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:733)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:4987)

上面的错误仅在我点击选择器的顶部或底部选择而不是当我滑动选择器时抛出,这很奇怪,因为当导游关闭时错误没有被抛出。

我为所有的numberpicker和datepicker调用此方法

 public void pickerfix(View np) {
    np.setSaveFromParentEnabled(false);
    np.setSaveEnabled(true);
    if (np.getId() == R.id.datepicker) {
        ((DatePicker) np).setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    } else {
        ((NumberPicker) np).setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
    }
  }

并且每个onValueChange上的这行代码都会解散导游..

 if(askTutorial == 1){
                tuts.dismissTourguide();}

nullpointer可能是什么原因?我尝试将一个onclicklistener放到拾取器上并放下解雇线,但没有运气。

!!!添加 所以这是我的datepicker代码

    Calendar c = Calendar.getInstance();
    int d = c.get(Calendar.YEAR);
    c.set(Calendar.YEAR, d - 2);
    Calendar c2 = Calendar.getInstance();
    c2.set(Calendar.YEAR, d - 130);
    datePicker.setMinDate(c2.getTimeInMillis());
    datePicker.setMaxDate(c.getTimeInMillis());
    datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
        @Override
        public void onDateChanged(DatePicker view,
                                  int year, int monthOfYear, int dayOfMonth) {
            if(askTutorial == 1){
                tuts.dismissTourguide();}
        }


    });

和我的号码选择器

 pickerfix(npKg);
    npKg.setMinValue(10);
 npKg.setMaxValue(650);
    npKg.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int i, int i1) {

            if(askTutorial == 1){
                tuts.dismissTourguide();}
        }
    });

通常我有超过1个数字选择器,但我认为这样做,。

我的导游展示会在与解雇电话相同的其他班级上进行。

    public void showProfileTutorial(View v, String bgcolor, int txt){

    Animation animation = new TranslateAnimation(0f, 0f, 200f, 0f);
    animation.setDuration(1000);
    animation.setFillAfter(true);
    animation.setInterpolator(new BounceInterpolator());

    Animation exitAnimation = new AlphaAnimation(1f, 0f);
    exitAnimation.setDuration(200);
    exitAnimation.setFillAfter(true);


    String[] splitter = texts[txt].split(":");
    toolTip = new ToolTip()
            .setTitle(splitter[0])
            .setDescription(splitter[1])
            .setTextColor(Color.parseColor("#bdc3c7"))
            .setBackgroundColor(Color.parseColor("#30BA8F"))
            .setShadow(true)
            .setGravity(grav1| grav2)
            .setEnterAnimation(animation);

    overlay = new Overlay()
            .disableClick(disableClick)
            .setBackgroundColor(Color.parseColor(bgcolor))
            .setStyle(Overlay.Style.Circle)
            .setExitAnimation(exitAnimation);

    pointer = new Pointer().setColor(Color.RED).setGravity(Gravity.CENTER | Gravity.CENTER);

    mTourGuideHandler = TourGuide.init(activity).with(TourGuide.Technique.Click);
    mTourGuideHandler.setPointer(null);
    mTourGuideHandler.setToolTip(toolTip);
    mTourGuideHandler.setOverlay(overlay);
    mTourGuideHandler.playOn(v);

}


public void dismissTourguide(){
    try{
        //.e("Before", "clean");
        mTourGuideHandler.cleanUp();
        //Log.e("After", "clean");
    }catch (Exception e){

    }
}

1 个答案:

答案 0 :(得分:1)

首先尝试这个修改,看它是否会起作用,但我认为它与并发问题有关 -

public void dismissTourguide(){
    try{
        if(null != mTourGuideHandler){
             mTourGuideHandler.cleanUp();
        }
    }catch (Exception e){}
}