我不能让我的启动画面工作,应用程序崩溃开始

时间:2015-10-13 13:07:01

标签: android android-layout splash-screen

我的应用程序在开始时崩溃了。 logcat指向此行setContentView(R.layout.activity_splash);。我是android的新手,现在已经差不多两个小时就遇到了这个问题。

的活动:

public class SplashActivity extends ActionBarActivity {

    /** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 1000;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_splash);

        /* New Handler to start the Menu-Activity
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(SplashActivity.this, LogInActivity.class);
                SplashActivity.this.startActivity(mainIntent);
                SplashActivity.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }





}

Xml布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/splash"
        android:id="@+id/splash"
        />






</LinearLayout>

logcat的:

      10-15 13:24:43.576    1968-1968/com.softeleven.developers.medicalreptracker E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.softeleven.developers.medicalreptracker, PID: 1968
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.softeleven.developers.medicalreptracker/com.softeleven.developers.medicalreptracker.SplashActivity}: java.lang.RuntimeException: Failed to resolve attribute at index 24
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 24
            at android.content.res.TypedArray.getColor(TypedArray.java:401)
            at android.widget.TextView.<init>(TextView.java:696)
            at android.widget.TextView.<init>(TextView.java:632)
            at android.widget.TextView.<init>(TextView.java:628)
            at android.widget.TextView.<init>(TextView.java:624)
            at android.widget.Toolbar.setTitle(Toolbar.java:565)
            at com.android.internal.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:261)
            at com.android.internal.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:243)
            at com.android.internal.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:670)
            at com.android.internal.policy.impl.PhoneWindow.setTitle(PhoneWindow.java:475)
            at android.app.Activity.onTitleChanged(Activity.java:5101)
            at android.app.Activity.onPostCreate(Activity.java:1123)
            at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1187)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-15 13:24:49.258    1968-1968/? I/Process﹕ Sending signal. PID: 1968 SIG: 9

Styles.xml

<resources>

    <!-- Base application theme. -->

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBar</item>
    </style>

    <style name="ActionBar" parent="android:Widget.ActionBar">
        <item name="android:background">@color/actionbar_color</item>
        <item name="android:icon">@android:color/transparent</item>
        <item name="android:titleTextStyle">@style/ActionBar.TitleText</item>
    </style>

    <style name="ActionBar.TitleText" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">18sp</item>
    </style>

</resources>

2 个答案:

答案 0 :(得分:1)

更改您的代码。而不是

public class SplashActivity extends Activity

public class SplashActivity extends ActionBarActivity {

答案 1 :(得分:0)

themes.xml

中尝试使用此配置
<style name="MyTheme" parent="Theme.AppCompat">
    ...
</style>

<style name="MyTheme.NoActionBar">
    <!-- Both of these are needed -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>