Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7188

Android studio Timer task crashes app on startup

$
0
0
public class MainActivity extends AppCompatActivity {private TextView timerTextView;private Button pauseStartBtn;private Button resetBtn;private Button productiveBtn;private CountDownTimer countDownTimer;private Boolean run;Timer timer = new Timer();private long timeMS = 0;private long seconds = 0;private long minutes = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    timerTextView = findViewById(R.id.timerTextView);    pauseStartBtn = findViewById(R.id.pauseStartBtn);    resetBtn = findViewById(R.id.resetBtn);    productiveBtn = findViewById(R.id.productiveBtn);    startUp();}TimerTask taskUp = new TimerTask() {    @Override    public void run() {        if (run){            timeMS++;            seconds = 0;            minutes = timeMS / 60;            if (timeMS < 60) {                seconds = timeMS;            } else seconds = timeMS - minutes * 60;            String form = String.format("%02d:%02d", minutes, seconds);            timerTextView.setText(form);        }    }};public void startUp(){    timer.scheduleAtFixedRate(taskUp,1000,1000);// change period back to 1000}

}

This is the whole code anyways whenever I run the app it instantly crashes.

If it matters, the app I'm trying to create is a chronometer of sorts and when I press a button it uses the time that I got from the chronometer to run a timer, and once that timer hits 00:00 it continues as a chronometer and I convert it to a timer, and so on.

I'm still in the very early stages but what I'm trying to do is to create a basic chronometer using the TimerTask and for some reason when I run the app it insta crashes. Any help is greatly appreciated!

Edit:

Log Cat

2020-04-09 18:25:46.428 5761-5870/? D/PowerKeeper.AppBgIdle: setUidState, uid = 10298 allow = false2020-04-09 18:25:50.569 4911-4911/? W/AppStateLoggerT: type=1400 audit(0.0:66626): avc: denied { read } for name="osrelease" dev="proc" ino=6324986 scontext=u:r:untrusted_app_27:s0:c165,c256,c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0


Viewing all articles
Browse latest Browse all 7188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>