当前位置: 代码迷 >> Android >> Intent跳转到除此以外Activity出错
  详细解决方案

Intent跳转到除此以外Activity出错

热度:81   发布时间:2016-04-28 07:48:53.0
Intent跳转到另外Activity出错
Java:

Button mybutton = (Button) findViewById(R.id.buttonPage1);
mybutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});

样式:

<TextView
    android:id="@+id/textViewPage1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="这是首页" />
<Button
    android:id="@+id/buttonPage1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textViewPage1"
    android:layout_below="@+id/textViewPage1"
    android:text="前往第二页" />

其他文件:
SecondActivity.java
activity_second.xml

出现的情况:
每次单击MainActivity的Button(前往第二页)按钮,程序总是错误退出。
出错信息如下:


请问这是什么原因呢?新学Android开发,谢谢大家。

------解决方案--------------------
SecondActivity.java要在Manifest里声明一下。
<activity android:name=".SecondActivity" />

------解决方案--------------------
二楼说的对。。
  相关解决方案