daimajia / NumberProgressBar

A beautiful, slim Android ProgressBar.
MIT License
6.07k stars 1.4k forks source link

Not Working with ButterKnifeZelezny #41

Closed segunmicheal27 closed 7 years ago

segunmicheal27 commented 7 years ago

I try to bind the control to butterKnief through annotation is not binding @BindView(R.id.NmumberProgressBar) NumberProgressBar bn;

Overide Oncreate bn(this);

and it throw null error argument Any Suggesting Please

Dona278 commented 7 years ago

I see that the id has a typo "R.id.NmumberProgressBar", are you sure that it is correct? Next, what is it bn(this)? Maybe you should use ButterKnife,inject(this) because bn is your NumberProgressBar widget and only after called ButterKnife,inject(this) you can access the binded widget.

segunmicheal27 commented 7 years ago

@Dona278 yeah I am 100% sure that my Id is correct And remember you will need to bind your progress variable to the main class the bn=> represent variable that hold the number progress bar and I call it like that

bn(this);

where this in the variable represent the self class binding I cant use ButterKnife.inject(this); because I am using version 8.4.0 butterknief

Here is the full code (in case for you to understand me):

With out ButterKnife (This Work fine):

private NumberProgressBar bnp;

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    bnp = (NumberProgressBar)findViewById(R.id.numberbar1);

    bnp.setOnProgressBarListener(this);

    timer = new Timer();

    timer.schedule(new TimerTask() {

        @Override

        public void run() {

            runOnUiThread(new Runnable() {

                @Override

                public void run() {

                    bnp.incrementProgressBy(1);

                }

            });

        }

    }, 1000, 100);

}

With Butter Knife now:

@BindView(R.id.numberbar1) NumberProgressBar bnp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

      ButterKnife.bind(this);

    bnp.setOnProgressBarListener(this);// This is where null error throw when using Butter Knife trick
    timer = new Timer();
    timer.schedule(new TimerTask() { 
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    bnp.incrementProgressBy(1);
                }
            });
        }
    }, 1000, 100);
}
segunmicheal27 commented 7 years ago

is like is now working I forget to call ButterKnife.bind(this); in my activity

daimajia commented 7 years ago

Thanks @Dona278 for your kind help. Issue close.