2016-11-20 132 views
0

@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);無法解析方法TimeUnit行

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()))); 
     } 
    }); 
} 

它的顯示無法解析方法,文本是紅色。我已應用Alt + Enter但不起作用。如何解決它。

+0

什麼是父類...? – MordechayS

+0

無法理解 –

+0

您正在嘗試使用哪種方法? – MordechayS

回答

0

你可能已經導入這個類:

java.util.concurrent.TimeUnit 

這一個替換:

import java.util.concurrent.TimeUnit; 
0

即使我在eclipse,在那裏我進口的TIMEUNIT被示數出面臨同樣的問題(即: import java.util.concurrent.TimeUnit不能被resverd)。 我已經能夠修復它後重新配置我的生成路徑工作區默認JRE [這是最新的在我的情況]。 Config構建路徑後 - 我得到了我的導入錯誤解決。附加卡BuildPathConfigration -

0

也許是最快的方法是使用此功能:

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); 
} 

你的代碼將被simplyfied到

tx2.setText(msToString(finalTime));