[英]when i add a splash screen on my android app the app crashes
i have created the app in android studio with java language and put a splash screen but when i run my app in android device the app crashed before adding the splash screen my app was running perfectly and i am running my app on my android device the android我设备上的版本是 android 10 这里是启动画面的代码。
package com.example.androiddevelopment;
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);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
Thread thread = new Thread(){
public void run(){
try {
sleep(4000);
}
catch (Exception e){
e.printStackTrace();
}
finally {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}
}
}; thread.start();
}
}
这是启动屏幕的 xml 代码我在约束布局中执行所有这些操作
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/maroon"
tools:context=".SplashActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Android Studio Development "
android:layout_marginTop="20dp"
android:textSize="30sp"
android:background="@drawable/textview_border"
android:textColor="@color/peach"
android:textStyle="bold"
android:gravity="center"
android:layout_marginLeft="10dp"
android:fontFamily="sans-serif"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foregroundGravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.497"
app:srcCompat="@drawable/as" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:gravity="right"
android:text="A project of IT-Souls"
android:textColor="@color/peach"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/imageView2"
app:layout_constraintHorizontal_bias="0.867"
app:layout_constraintStart_toStartOf="@+id/imageView2"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
这是 android 清单:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidDevelopment">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chapter2" />
<activity android:name=".Chapter1" />
<activity android:name=".MainActivity">
</activity>
这是logcat错误:
2021-03-24 03:19:01.937 1338-1502/? E/WifiVendorHal: getWifiLinkLayerStats(l.939) failed {.code = ERROR_NOT_SUPPORTED, .description = } 2021-03-24 03:19:02.076 537-537/? E/WifiHW: get chiptype error 2021-03-24 03:19:02.518 27621-27640/? E/HiApp.HUKSUtil: pool-5-thread-1{2116} <<< ERROR >>> getCertificateChain InvocationTargetException 2021-03-24 03:19:02.519 27621-27640/? E/HiApp.HUKSUtil: pool-5-thread-1{2116} <<< ERROR >>> X509Certificate is null! 2021-03-24 03:23:11.533 1338-3989/? E/HwProtectAreaService: nativeReadProtectAreaJava:error ret is -1 ! 2021-03-24 03:23:11.646 1338-5981/? E/HwProtectAreaService: nativeReadProtectAreaJava:error ret is -1 ! 2021-03-24 03:26:11.569 1338-1364/? E/libprocessgroup: Error encountered killing process cgroup uid 99025 pid 26108: No such file or directory 2021-03-24 03:26:11.630 26995-26995/? E/b$15: ║ onServiceDisconnected error : 2021-03-24 03:26:12.071 27970-27970/? E/RePlugin.PluginInfoList: load: Read Json error!
您可以使用Logcat
,以便您可以查看class,代码行以及错误是什么,然后对其进行调试。 抱歉,我无法发表评论,因为我的声望低于 50。 Logcat
位于程序的左下角
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.