我做了个android intent的简单例子老是出错
public class mytest extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button startBtn = (Button)findViewById(R.id.Button01);
startBtn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button01:
Intent intent = new Intent(this, haha.class);
startActivity(intent);
break;
default:
break;
}
}
}
main.xml=========================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Button01"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
haha.class:==========================================
public class haha extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
}
test.xml==========================
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="@+id/Button01" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
请问哪里出了?...........................
[解决办法]
haha 这个activity 你声明了吗?
[解决办法]
同意楼上的,检查下AndroidManifest.xml文件是否添加了haha Activity 的声明。
[解决办法]
代码没有错
[解决办法]
在AndroidManifest.xml内添加
<activity android:name="haha"></activity>