0

Here is my handler code in which i set my progressbar in oncreate() method

     progressBar = (ProgressBar) findViewById(R.id.progressBar);
     thread = new Thread(new MyThread());
     thread.start();
     handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            progressBar.setProgress(msg.arg1);

                          }
       };

      if(progressBar.getProgress()==99)
    {
        Intent i = new Intent(SplashScreen.this,MainActivity.class);
        startActivity(i);
        finish();

    }

And here is the MyThread Class through which i sending message to handler

class MyThread implements Runnable{


    @Override
    public void run() {

        for (int i=0;i<100;i++){

            Message message = Message.obtain();

            message.arg1 = i;
            handler.sendMessage(message);


            try {

                Thread.sleep(100);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
    }
}//mythread

I want to start my main activity when progressbar complete its progress. but mesage.arg1 returns null Tell me where i am making mistake

This is the screen shot which andriod studio is generating to me

  • 1
    it cannot return null as it is an integer: `public int arg1` – pskink Jun 17 '16 at 06:51
  • Your handler instance is null in the run method. Move the thread.start() to a line after you initialize your handler. It seems that the thread fires right away which results in handler being null. – GPuschka Jun 17 '16 at 07:01

0 Answers0