更改为初始屏幕后,应用程序将无法运行

时间:2019-06-16 19:32:48

标签: android

我实现了初始屏幕并对其进行了更改,以使其仅在应用程序加载时运行。现在,该应用程序将根本无法运行。所有更改were based on this short tutorial

我迷路了,要求指导故障排除。以下是我修改过的文件

清单

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="app"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashActivity"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="AppName"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

SplashActivity.java

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

Background_splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/gray"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

Styles.XML

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorAccent</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

</resources>

日志

2019-06-16 15:35:12.476 32169-32169/com.jstudios.AppName E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.jstudios.AppName, PID: 32169
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jstudios.AppName/com.jstudios.AppName.SplashActivity}: android.content.res.Resources$NotFoundException: Drawable com.jstudios.AppName:drawable/background_splash with resource ID #0x7f07005d
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3108)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7045)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.jstudios.AppName:drawable/background_splash with resource ID #0x7f07005d
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/background_splash.xml from drawable resource ID #0x7f07005d
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:898)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:677)
        at android.content.res.Resources.getDrawableForDensity(Resources.java:903)
        at android.content.res.Resources.getDrawable(Resources.java:842)
        at android.content.Context.getDrawable(Context.java:628)
        at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
        at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
        at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
        at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
        at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
        at com.jstudios.AppName.SplashActivity.onCreate(SplashActivity.java:12)
        at android.app.Activity.performCreate(Activity.java:7327)
        at android.app.Activity.performCreate(Activity.java:7318)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3088)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3251)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7045)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <bitmap> requires a valid 'src' attribute
        at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:849)
        at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:770)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:146)
2019-06-16 15:35:12.477 32169-32169/com.jstudios.AppName E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1359)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1348)
        at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:279)
        at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:146)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1359)
        at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1318)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:879)
            ... 27 more

0 个答案:

没有答案