2

good afternoon I have two classes, one that implement one progressBar this class I intend to create a public method that will run startActivity(). the main class would have a button that would call the method. However this giving error null reference.

ProgressBarUtil:

public class ProgressBarUtil extends BaseActionBarActivity {
private ProgressBar progressBar;
private Handler handler;
private int progress;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress_bar_util);
    inicializaComponentes();
}

public void inicializaComponentes() {

    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    progressBar.setIndeterminate(true);
    handler = new Handler();

    executaProgressbar();
}

public void startProgressBar(){
    startActivity(new Intent(getBaseContext(),ProgressBarUtil.class));
}

private void executaProgressbar() {

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                finish();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

}

class that will call the method starProgressBar

The other class

 @Override
public void onClick(View view) {
    int id = view.getId();
    if (btnDownload.getId() == id){
         new ProgressBarUtil().startProgressBar();
    }
}
  • Why are you even trying to do it this way? Just add `startActivity(new Intent(getBaseContext(),ProgressBarUtil.class));` to your `onClick()` – codeMagic Jul 02 '15 at 18:58
  • I was thinking of doing this to create one working for me instead of staying calling startActivity in every class that I need to use the progressBar call a metedo within the class that would be responsible for it. This would make it easy for several developers team started using and enjoying only the internal method of the class. @codeMagic –  Jul 03 '15 at 12:15

0 Answers0