在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):致命异常:主要 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):at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405) 12-31 12:39:52.475:E / AndroidRuntime(25978):at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379) 12-31 12:39:52.475:E / AndroidRuntime(25978):at 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.example.bt.MainActivity $ 1.handleMessage(MainActivity.java:147) 12-31 12:39:52.475:E / AndroidRuntime(25978):at android.os.Handler.dispatchMessage(Handler.java:99)12-31 12:39:52.475:E / AndroidRuntime(25978):at android.os.Looper.loop(Looper.java:130)12-31 12:39:52.475: E / AndroidRuntime(25978):at android.app.ActivityThread.main(ActivityThread.java:3806)12-31 12:39:52.475:E / AndroidRuntime(25978):at java.lang.reflect.Method.invokeNative(Native Method)12-31 12:39:52.475:E / AndroidRuntime(25978):at java.lang.reflect.Method.invoke(Method.java:507)12-31 12:39:52.475: E / AndroidRuntime(25978):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 12-31 12:39:52.475:E / AndroidRuntime(25978):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)12-31 12:39:52.475:E / AndroidRuntime(25978):at dalvik.system.NativeStart.main(原生方法)
答案 0 :(得分:1)
将您的开始活动代码更改为:
Intent medPlay = new Intent(MainActivity.this,
com.example.bt.MediaPlayer.class);
startActivity(medPlay);
并将AndroidPifest中的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
活动
答案 1 :(得分:1)
无法找到明确的活动类{com.example.bt/android.media.MediaPlayer};
您导入/指定了错误的MediaPlayer!