这是一个奇怪的问题,但LogCat中的getActivity()
调用显示为android.support.v4.app.FragmentActivity
,使其返回空对象引用...
这是抛出异常的代码......
public void updateTimerLabel()
{
Thread duration = new Thread() {
@Override
public void run() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
long currentDuration = mp.getCurrentPosition();
timerFooter.setText(""+utils.milliSecondsToTimer(currentDuration));
mHandler.postDelayed(this, 100);
}
});
}
};
duration.start();
}
这是LogCat条目......
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.FragmentActivity.runOnUiThread(java.lang.Runnable)' on a null object reference
at testapplication.fragments.FragmentA$6.run(FragmentA.java:442)
如您所见,我致电getActivity()
,并且在整个代码中都没有提到FragmentActivity
。任何解决方案?