(http://img.ask.csdn.net/upload/201505/31/1433054546_331226.png) 和書上對比了好多次了-。-
第一個
```package com.example.ex04_01;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button but;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but = (Button) findViewById(R.id.but);
but.setOnClickListener(new mClick());
}
class mClick implements OnClickListener {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Second.class);
startActivity(intent);
}
}
}
第二個
```package com.example.ex04_01;
import android.app.Activity;
import android.os.Bundle;
class Second extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
}
你沒有在你的AndroidManifest.xml中 聲明你的第二個activity吧
例如:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 第二個activity -->
<activity
android:name="xxx">
</activity>
</application>