0

OK、Androidアプリで理解できない問題が発生しています。MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig)以下のコードでは、 ;でエラーが発生しています。

createの上にカーソルを置くと、次のようになります。

create(Context, int)タイプのメソッドMediaPlayerは引数には適用できません(new View.OnFocusChangeListener(){}, int

それはどういう意味ですか、そしてもっと重要なことに、どうすればそれを解決できますか?

ルーチン全体は次のとおりです。

    TextView tv=(TextView)findViewById(R.id.weight);
    tv.setOnFocusChangeListener(new OnFocusChangeListener(){
      @Override
      public void onFocusChange(View v,boolean hasFocus){
            /* When focus is lost check that the text field
             * has valid values.
             */
            if (!hasFocus) {
                float tempweight = Float.parseFloat(et_weight.getText().toString());
                if(tempweight > 200){
                    MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig);
                    mpWeight.start();
                }
            }
      }          
    });
4

1 に答える 1

0

のはのインスタンスに対応しますthisが、アプリケーションコンテキストを渡す必要があります。MediaPlayer.create(this, R.raw.mppig);OnFocusChangeListener

作成呼び出しをに変更します

MediaPlayer.Create(getApplicationContext(), R.raw.mppig);

于 2011-08-08T13:52:06.817 に答える