Android应用开发错误 - 此行有多个标记

时间:2012-03-17 01:23:13

标签: java android eclipse

我刚开始使用android在eclipse中进行android开发,我正在尝试编程一个按钮,这是我的代码,

        package my.Apprentice;

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.Button;

    public class ApprenticeVoteActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);



            startVotingListener();


        }

        private void startVotingListener() {

            final Button startVoting = (Button) findViewById(R.id.startVoting);

            startVoting.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                } // Multiple markers at this line error shows here
            };)
        }
        }

上面评论了我的错误的位置。我真的不知道如何摆脱它,我已经尝试清理我的项目没有成功。有没有人有任何想法?谢谢!

更新后的工作代码如下所示:

    package my.Apprentice;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class ApprenticeVoteActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        startVotingListener();

    }

    private void startVotingListener() {

        final Button startVoting = (Button) findViewById(R.id.startVoting);

        startVoting.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}

2 个答案:

答案 0 :(得分:1)

尝试});

import android.view.View;
import android.view.View.OnClickListener;

startVoting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        } // Multiple markers at this line error shows here
    }); // Sequence is wrong

答案 1 :(得分:0)

您是否尝试删除';'听众宣言后?同时删除视图参考:

startVoting.setOnClickListener(new View.OnClickListener() { <-- HERE

            @Override
            public void onClick(View v) {

            } // Multiple markers at this line error shows here
        };) // <--- HERE

决赛:

startVoting.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

            }
        });