当我在我的 android 应用程序上添加启动画面时,应用程序崩溃了
when i add a splash screen on my android app the app crashes
我已经在 android studio 中使用 java 语言创建了该应用程序并放置了启动画面,但是当我 运行 我的应用程序在 android 设备中时,该应用程序之前崩溃了添加启动画面我的应用程序 运行ning 完美,我正在 运行ning 我的应用程序在我的 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" />
这是 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: ║ onServiceDisconnected error : 2021-03-24 03:26:12.071 27970-27970/? E/RePlugin.PluginInfoList: load: Read Json error!
你可以使用Logcat
,这样你就可以看到在class,代码行,错误是什么,然后调试它。抱歉,我无法发表评论,因为我的声望不到 50。 Logcat
位于程序的左下方
我已经在 android studio 中使用 java 语言创建了该应用程序并放置了启动画面,但是当我 运行 我的应用程序在 android 设备中时,该应用程序之前崩溃了添加启动画面我的应用程序 运行ning 完美,我正在 运行ning 我的应用程序在我的 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" />
这是 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: ║ onServiceDisconnected error : 2021-03-24 03:26:12.071 27970-27970/? E/RePlugin.PluginInfoList: load: Read Json error!
你可以使用Logcat
,这样你就可以看到在class,代码行,错误是什么,然后调试它。抱歉,我无法发表评论,因为我的声望不到 50。 Logcat
位于程序的左下方