如何解决当我在我的 android 应用程序上添加启动画面时,应用程序崩溃了
我已经在 android studio 中使用 java 语言创建了应用程序并放置了启动画面,但是当我在 android 设备中运行我的应用程序时,应用程序在添加启动画面之前崩溃了,我的应用程序运行良好,我正在我的 android 上运行我的应用程序设备 我的设备上的 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" />
这是安卓清单:
<?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
,以便您可以查看在哪个类、代码行以及错误是什么,然后对其进行调试。抱歉,我无法发表评论,因为我的声望不到 50。 Logcat
位于程序的左下方
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。