2016-11-20 15 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

にsimplyfiedされます...親クラスとは何ですか? – MordechayS

+0

Cann't understand –

+0

あなたのIDEはどちらの方法に関係していますか? – MordechayS

答えて

0
あなたはこのクラスにインポートしているかもしれません

java.util.concurrent.TimeUnit 

はこの1つでそれを置き換えます。でも、私はTimeUnitでは私のインポートが出erroringた日食、同じ問題に直面し

import java.util.concurrent.TimeUnit; 
0

を(すなわち: import java.util.concurrent.TimeUnitは削除できません)。 Build PathをデフォルトのJRE Workspace [私の場合は最新のもの]に再構成した後で修正できました。 設定ビルド後のパス - インポートエラーが解決されました。取り付けスナップ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); 
} 

あなたのコードは

tx2.setText(msToString(finalTime)); 
関連する問題