在 switch 语句中的 MainActivity 类中,我声明并初始化了一个 Intent 以开始另一个活动。这是片段:
case MESSAGE_DEVICE_NAME:
//save connected device name
mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
Toast.makeText(getApplicationContext(), "Connected to "+mConnectedDeviceName, Toast.LENGTH_SHORT).show();
Intent medPlay = new Intent(MainActivity.this, MediaPlayer.class);
startActivity(medPlay);
break;
这是 MediaPlayer 类:
public class MediaPlayer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_player);
}
}
这是 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bt"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-sdk
android:minSdkVersion="6"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.bt.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
android:name=".DeviceListActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/select_device"
android:theme="@android:style/Theme.Light" />
<activity
android:name=".MediaPlayer"
android:configChanges="orientation|keyboardHidden"
android:label="@string/media_player"
android:theme="@android:style/Theme.Light" />
</application>
</manifest>
但是我在 LogCat 控制台上不断收到此错误:
12-31 12:39:52.475: E/AndroidRuntime(25978): 致命异常: main 12-31 12:39:52.475: E/AndroidRuntime(25978): android.content.ActivityNotFoundException: 找不到明确的活动类 {com .example.bt/android.media.MediaPlayer}; 您是否在 AndroidManifest.xml 中声明了此活动?12-31 12:39:52.475: E/AndroidRuntime(25978): 在 android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 12-31 12:39:52.475: E/AndroidRuntime(25978): 在 android. app.Instrumentation.execStartActivity(Instrumentation.java:1379) 12-31 12:39:52.475: E/AndroidRuntime(25978): 在 android.app.Activity.startActivityForResult(Activity.java:2893) 12-31 12:39: 52.475: E/AndroidRuntime(25978): at android.app.Activity.startActivity(Activity.java:3003) 12-31 12:39:52.475: E/AndroidRuntime(25978): at com.