E/AndroidRuntime: FATAL EXCEPTION: main
Process: jp.co.pipm.paas, PID: 10531
java.lang.IllegalStateException: Fragment NewsActivityNewestListFragment{fa597a7} not attached to a context.
at androidx.fragment.app.Fragment.requireContext(Fragment.java:696)
at androidx.fragment.app.Fragment.getResources(Fragment.java:760)
at androidx.fragment.app.Fragment.getString(Fragment.java:782)
at jp.co.pipm.paas.paas.news_activity.NewsActivityNewestListFragment$CountDown.onTick(NewsActivityNewestListFragment.kt:345)
at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:130)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
here is my count down timer method:
/**
* カウントダウンタイマー
*/
inner class CountDown(millisInFuture: Long, countDownInterval: Long):
CountDownTimer(millisInFuture, countDownInterval) {
override fun onFinish() {
view?.findViewById(R.id.btn_adbance)?.text = getString(R.string.project_news_list_countdown_end)
view?.findViewById(R.id.btn_adbance)?.setBackgroundColor(resources.getColor(R.color.red))
// 応募時間超過
Log.d(“NewsActivity”, “CountDownTimer/応募時間超過${toDisplayItem.main.receiptId}”)
displayTimeOverDialog()
}
override fun onTick(millisUntilFinished: Long) {
// 残り時間を表示
remainingTime = millisUntilFinished
val mes = "${getString(R.string.project_news_list_countdown_timer_mes)} " + String.format(
" %02d:%02d:%03d",
(millisUntilFinished/60000).toInt(),
(millisUntilFinished/1000).toInt(),
(millisUntilFinished % 1000).toInt()
)
view?.findViewById<Button>(R.id.btn_adbance)?.text = mes
}
}