在我的应用程序中,它会打开一个启动画面,然后是 MainActivity。我写了以下代码
SplashActivity.java
public class SplashActivity extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
MainActiviy.java
我添加了 MainActivity 和 SplashActivity 以显示如下:
<activity
android:name="com.emy.healthytips.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.emy.healthytips.MainActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTop">
<meta-data
android:name="android.app.default_searchable"
android:value=".MainActivity" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="com.emy.healthytips.MainActivity"
android:scheme="oauth" />
</intent-filter>
</activity>
但它给了我以下异常
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.emy.healthytips.MainActivity
at com.emy.healthytips.SplashActivity$1.run(SplashActivity.java:20)
在这一行
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
我怎样才能解决这个问题?希望任何人都可以帮助我。提前致谢。