下面是我的活动代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
b3 = (Button) findViewById(R.id.button3);
b4 = (Button) findViewById(R.id.button4);
iv = (ImageView) findViewById(R.id.imageView);
tx1 = (TextView) findViewById(R.id.textView2);
tx2 = (TextView) findViewById(R.id.textView3);
tx3 = (TextView) findViewById(R.id.textView4);
tx3.setText("song.mp3");
mediaPlayer = MediaPlayer.create(this, R.raw.song);
seekBar = (SeekBar) findViewById(R.id.seekBar);
seekBar.setClickable(false);
b2.setEnabled(false);
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Playing Now", Toast.LENGTH_LONG).show();
mediaPlayer.start();
finalTime = mediaPlayer.getDuration();
startTime = mediaPlayer.getCurrentPosition();
if (oneTimeOnly == 0){
seekBar.setMax((int) finalTime);
oneTimeOnly = 1;
}
/* Problem below line */
tx2.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECOND.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toMinutes((long) finalTime) -
TimeUnit.MINUTE.toSeconds(TimeUnit.MILLISECONDS.toMinutes())));
}
});
}它在我使用toMinutes的行上显示错误cannot resolve method。文本是红色的。我已经申请了Alt+Enter,但不起作用。你知道怎么解决这个问题吗?
发布于 2017-05-21 19:21:51
您可能已经导入了此类:
java.util.concurrent.TimeUnit将其替换为以下内容:
import java.util.concurrent.TimeUnit;发布于 2018-03-05 02:57:12
甚至我在eclipse中也遇到了同样的问题,我对TimeUnit的导入出错了(即:导入java.util.concurrent.TimeUnit不能被重新钟爱)。在将构建路径重新配置到Workspace default JRE (在我的案例中是最新的)之后,我能够修复它。在配置构建路径之后-我解决了导入错误。附加捕捉

-
发布于 2018-03-05 21:12:50
也许最快的方法是使用这个函数:
String msToString(int ms) {
int hh = ms / 3600000;
ms -= hh * 3600000;
int mm = ms / 60000;
ms -= mm * 60000;
int ss = ms / 1000;
return String.format("%d min, %d sec", mm, ss);
}您的代码将简化为
tx2.setText(msToString(finalTime));https://stackoverflow.com/questions/40701527
复制相似问题