我正在使用android应用程序的闪屏代码,它的代码发布在堆栈溢出上。我无法得到输出。下面是代码。
package com.splash;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 3000;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent mainIntent = new Intent(Splashscreen.this,
MainActivity.class);
Splashscreen.this.startActivity(mainIntent);
Splashscreen.this.finish();
overridePendingTransition(R.anim.mainfadein,
R.anim.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}
}
}下面是splash.xml文件;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splash" />
</LinearLayout>请告诉我怎么解决。我还为闪屏图像提供了fadein和fadeout xml文件。
发布于 2012-06-10 17:12:18
在您的代码中public class SplashScreen extends Activity {两次..
让它变得单一。
package com.splash;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 3000;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent mainIntent = new Intent(Splashscreen.this,
MainActivity.class);
Splashscreen.this.startActivity(mainIntent);
Splashscreen.this.finish();
overridePendingTransition(R.anim.mainfadein,
R.anim.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}
}发布于 2012-06-10 18:41:17
确保在AndroidManifest.xml中添加了MainActivity。此外,发布来自logcat的异常堆栈跟踪也会有很大帮助。
发布于 2013-02-19 00:55:08
最有可能的情况是,您没有“MainActivity”类。检查它的名称是否正确。并确保它在正确的包中并添加到清单中。
https://stackoverflow.com/questions/10967537
复制相似问题