当我尝试在模拟器上运行时,我收到此错误:
03-24 11:42:49.843 1120-1120 / com.mindrain.touchbreak E / AndroidRuntime:FATAL EXCEPTION:main android.content.ActivityNotFoundException:无法找到显式活动类{com.mindrain.touchbreak / android.view.Menu};你有没有在AndroidManifest.xml中声明这个活动? 在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618) 在android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 在android.app.Activity.startActivityForResult(Activity.java:3370) 在android.app.Activity.startActivityForResult(Activity.java:3331) 在android.app.Activity.startActivity(Activity.java:3566) 在android.app.Activity.startActivity(Activity.java:3534) 在com.mindrain.touchbreak.Splash $ 1.run(Splash.java:26) 在android.os.Handler.handleCallback(Handler.java:725) 在android.os.Handler.dispatchMessage(Handler.java:92) 在android.os.Looper.loop(Looper.java:137) 在android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 在dalvik.system.NativeStart.main(本地方法)
在我的宣言中,我有这个:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mindrain.touchbreak"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.write_external_storage"/>
<uses-permission android:name="android.permission.read_external_storage"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.set_orientation"/>
<uses-sdk android:minSdkVersion="3"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainMenu"
android:label="@string/app_name" >
</activity>
<activity
android:name=".Splash"
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=".Splash2"
android:label="@string/app_name">
</activity>
</application>
</manifest>
在我的Splash活动中,我有这个:
package com.mindrain.touchbreak;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 1000;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash_screen);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
private void openApp(){
startActivity(new Intent(this,Splash2.class));
finish();
}
}
在我的Splash2活动中:
package com.mindrain.touchbreak;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaActionSound;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash2 extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 1000;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash_screen_2);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
Intent mainIntent = new Intent(Splash2.this,MainMenu.class);
Splash2.this.startActivity(mainIntent);
Splash2.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
private void openApp(){
finish();
startActivity(new Intent(this,MainMenu.class));
}
}
在我的MainMenu活动中:
package com.mindrain.touchbreak;
import android.app.Activity;
import android.media.MediaPlayer;
import android.view.View;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainMenu extends Activity implements View.OnClickListener {
public MediaPlayer mp = null;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.start:
//startActivity(Game);
break;
case R.id.options:
//startActivity();
break;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
Button b = (Button) findViewById(R.id.sound);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mp == null) {
//mp = MediaPlayer.create(MainMenu.this, R.raw.menu);
mp.start();
} else {
mp.stop();
mp = null;
}
}
});
}
}
错误在哪里?
由于
答案 0 :(得分:1)
我认为你应该改变
Intent mainIntent = new Intent(Splash.this,Menu.class);
到
Intent mainIntent = new Intent(Splash.this,MainMenu.class);
在Splash Activity中。