当前位置: 代码迷 >> Android >> 同一段跳转代码为何换到另一个程序就无法运行了?
  详细解决方案

同一段跳转代码为何换到另一个程序就无法运行了?

热度:98   发布时间:2016-04-27 22:32:52.0
同一段跳转代码为什么换到另一个程序就无法运行了???
public class MainActivity extends ActionBarActivity {
    private  ImageButton speech01;
    private  ImageButton speech02;
    private  ImageButton sheet01;
    private  ImageButton sheet02;
    private  ImageButton information01;
    private  ImageButton information02;
    private  ImageButton class01;
    private  ImageButton class02;
    private  Button search;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        speech01 = (ImageButton)findViewById(R.id.speech01);
        speech02 = (ImageButton)findViewById(R.id.speech02);
        speech01 = (ImageButton)findViewById(R.id.speech01);
        speech02 = (ImageButton)findViewById(R.id.speech02);
        information01 = (ImageButton)findViewById(R.id.information01);
        information02 = (ImageButton)findViewById(R.id.information02);
        class01 = (ImageButton)findViewById(R.id.class01);
        class02 = (ImageButton)findViewById(R.id.class02);

        speech01.setOnClickListener(click);
        speech02.setOnClickListener(click);
        speech01.setOnClickListener(click);
        speech02.setOnClickListener(click);
        information01.setOnClickListener(click);
        information02.setOnClickListener(click);
        class01.setOnClickListener(click);
        class02.setOnClickListener(click);
    }
    private View.OnClickListener click = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch ((v.getId())){
                case R.id.speech01:
                case R.id.speech02:
                case R.id.sheet01:
                case R.id.sheet02:
                case R.id.information01:
                case R.id.information02:
                case R.id.class01:
                case R.id.class02:
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this, PlayActivity.class);
                    startActivity(intent);
                    break;
                default:
                    break;
            }
        }
    };

------解决思路----------------------
无法运行,logcat有什么提示
------解决思路----------------------
应该是:android只会到Activity中去找onClick方法,而不会到Fragment中去找。是不是把代码拷贝到Fragment中去了。
------解决思路----------------------
HomePageActivity这个文件中的错误,而不是MainActivity中的错误。
  相关解决方案