0

スレッドでこのエラーが発生するのはなぜですか?

正しい構文を使用しましたが、エラーがあるようです! :(

これがスクリーンショットです ==> http://i.imgur.com/ccPOz.png?1

編集: コードは次のとおりです。

`

package com.pc.threads;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Thread music_2 = new Thread(){
            try{

            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent music_i = new Intent(MainActivity.this,NewActivity.class);
            }
        };
    }

`

4

1 に答える 1

5

Java では、コードはメソッド内に入ります。スレッド クラスを定義 (インライン化) するときに、コードをラップするメソッド「run」を定義するのを忘れていました。

Thread t= new Thread() {
    public void run() {
    ///your code goes here
    }
};
于 2013-01-02T16:59:28.357 に答える