Я создаю приложение React Native и использую React Native Splash Screen для моего заставки.
Позвольте сначала дать вам мой код, а затем я объяснювыпуск.
res/drawable/background_splash.xml
:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue" />
<item
android:width="200dp"
android:height="200dp"
android:drawable="@mipmap/icon_splash"
android:gravity="center" />
</layer-list>
SplashActivity.java
:
package com.painbutton;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.java
:
package com.painbutton;
import com.facebook.react.ReactActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is
* used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "painbutton";
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
}
AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.painbutton">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme"
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=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:exported="true">
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
Мое изображение находится внутри res/
, а затем у меня есть один icon.png для каждой плотности пикселей.
Когда я знаю, что приложение запускается, оно выдает сообщение «к сожалению,Painbutton остановлен.
Вот журнал ошибок:
10-11 12:51:10.441 537-537/com.painbutton E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.painbutton, PID: 537
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.painbutton/com.painbutton.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001d type #0x1 is not valid
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f09001d type #0x1 is not valid
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2779)
at android.content.res.Resources.getLayout(Resources.java:1165)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Dialog.setContentView(Dialog.java:512)
at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32)
at android.app.Activity.runOnUiThread(Activity.java:5511)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49)
at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:56)
at com.painbutton.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Что происходит?Почему происходит сбой моего приложения?