0

在 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.

4

2 回答 2

1

将您的开始活动代码更改为:

Intent medPlay = new Intent(MainActivity.this,
                               com.example.bt.MediaPlayer.class);
startActivity(medPlay);

并在 AndroidManifest 中将 MediaPlayer 声明为:

<activity
    android:name="com.example.bt.MediaPlayer"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/media_player"
    android:theme="@android:style/Theme.Light" />

因为在日志消息中:

android.content.ActivityNotFoundException:找不到明确的活动类 {com.example.bt/android.media.MediaPlayer};您是否在 AndroidManifest.xml 中声明了此活动?

系统正在尝试启动默认MediaPlayer活动

于 2012-12-31T12:56:11.207 回答
1

找不到显式活动类 {com.example.bt/android.media.MediaPlayer }

您导入/指定了错误的 MediaPlayer!

于 2012-12-31T12:57:19.403 回答