获取错误构造函数Intent(new View.OnClickListener(){},Class <numberboardactivity>)在android应用程序代码中未定义:</numberboardactivity>

时间:2014-02-21 00:23:42

标签: android android-intent

import android.app.Activity;

import android.content.Intent;

import android.view.View;

import android.view.View.OnClickListener;

import android.os.Bundle;

import android.widget.Button;

import android.widget.RadioButton;

import android.widget.RadioGroup;

import android.widget.Toast;


public class NumberModeSizeOptionsActivity extends Activity {

    private RadioGroup radioGroupId;
    private RadioButton radioBoard;
    private Button button;

    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board_option);

        addButtonListener();

      }


    public void addButtonListener() {

           radioGroupId = (RadioGroup) findViewById(R.id.radioBoard);       
           button = (Button) findViewById(R.id.btnStart);

           button.setOnClickListener(new OnClickListener() {

                @Override
             public void onClick(View v) {

                   // get the selected radio button from the group

                  int selectedOption = radioGroupId.getCheckedRadioButtonId();


                  // find the radiobutton by the previously returned id     
                  radioBoard = (RadioButton) findViewById(selectedOption);
                  startActivity(new Intent(this, NumberBoardActivity.class));
                  //startActivity(new Intent("org.test.slidingtiles.NumberBoardActivity"));
                  Toast.makeText(NumberModeSizeOptionsActivity.this, radioBoard.getText(), Toast.LENGTH_SHORT).show();
            }

        });

    }


}

2 个答案:

答案 0 :(得分:1)

将startIntent更改为此

startActivity(new Intent(NumberModeSizeOptionsActivity.this, NumberBoardActivity.class));

答案 1 :(得分:0)

尝试以下代码:(更改intent语句)并检查是否在android manifest.xml中定义了第二个活动NumberBoardActivity:

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.board_option);
    radioGroupId = (RadioGroup) findViewById(R.id.radioBoard);       
    button = (Button) findViewById(R.id.btnStart);

     button.setOnClickListener(new OnClickListener() {

            @Override
         public void onClick(View v) {

               // get the selected radio button from the group

              int selectedOption = radioGroupId.getCheckedRadioButtonId();


              // find the radiobutton by the previously returned id     
              radioBoard = (RadioButton) findViewById(selectedOption);
              startActivity(new Intent(NumberModeSizeOptionsActivity.this, NumberBoardActivity.class));
              //startActivity(new Intent("org.test.slidingtiles.NumberBoardActivity"));
              Toast.makeText(NumberModeSizeOptionsActivity.this, radioBoard.getText(), Toast.LENGTH_SHORT).show();
        }

    });

  }

}