E/AndroidRuntime:致命异常:主进程:[=11=],PID:14488
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.gameshopservicesdz, PID: 14488
- 我正在制作一个 运行 欢迎屏幕的应用程序,但是当我尝试 运行 我的应用程序 android 7.0 甚至 7.1 版本时,它在 setcontentview( activity_main); !
- 但是当我尝试 运行 我的应用程序 android 版本 11 时,它开始时出现任何问题。
我的应用程序原始序列 运行 版本。 11
如果我打开启动画面欢迎后出现启动画面错误activity
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gameshopservicesdz, PID: 13950
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gameshopservicesdz/com.example.gameshopservicesdz.SplashScreenActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2698)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6190)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.gameshopservicesdz-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.gameshopservicesdz-2/lib/x86, /data/app/com.example.gameshopservicesdz-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.gameshopservicesdz.SplashScreenActivity.onCreate(SplashScreenActivity.java:18)
at android.app.Activity.performCreate(Activity.java:6698)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6190)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
SplashScreenActivty.java :
//error in setContentView(R.layout.activity_splash_screen);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
getSupportActionBar().hide();
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.white_2));
SharedPreferences preferences = getSharedPreferences("intro", MODE_PRIVATE);
String intro = preferences.getString("state", "");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//if second time
if (intro.equals("done")) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} else {
//if first time
Intent intent = new Intent(getApplicationContext(), IntroScreenActivity.class);
startActivity(intent);
finish();
}
}
}, 2300);
}
}
将您的 android.support.constraint.ConstraintLayout
更改为 androidx.constraintlayout.widget.ConstraintLayout
我认为您在编写此代码时参考了一些旧文档或教程。
你应该做的第一件事是使用 androidx.constraintlayout.widget.ConstraintLayout
而不是 android.support.constraint.ConstraintLayout
,因为 android.support.constraint.ConstraintLayout
被标记为已弃用(即不应该使用它,它将被删除和以后不可用。)
回到你的问题,这是因为Android无法找到ConstraintLayout的class引起的。由于 ConstraintLayout
不是 Android SDK 的一部分,您需要在应用程序的 build.gradle
文件(位于 app/build.gradle
或 app/build.gradle.kts
) 通过使用以下代码:
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
添加后,只需同步您的项目并重建即可。这将解决您的问题。
此外,您可以在 https://developer.android.com/training/constraint-layout
阅读更多关于约束布局的信息
- 我正在制作一个 运行 欢迎屏幕的应用程序,但是当我尝试 运行 我的应用程序 android 7.0 甚至 7.1 版本时,它在 setcontentview( activity_main); !
- 但是当我尝试 运行 我的应用程序 android 版本 11 时,它开始时出现任何问题。
我的应用程序原始序列 运行 版本。 11
如果我打开启动画面欢迎后出现启动画面错误activity
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gameshopservicesdz, PID: 13950
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gameshopservicesdz/com.example.gameshopservicesdz.SplashScreenActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2698)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6190)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.gameshopservicesdz-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.gameshopservicesdz-2/lib/x86, /data/app/com.example.gameshopservicesdz-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:609)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.gameshopservicesdz.SplashScreenActivity.onCreate(SplashScreenActivity.java:18)
at android.app.Activity.performCreate(Activity.java:6698)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2759)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6190)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
SplashScreenActivty.java :
//error in setContentView(R.layout.activity_splash_screen);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
getSupportActionBar().hide();
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.white_2));
SharedPreferences preferences = getSharedPreferences("intro", MODE_PRIVATE);
String intro = preferences.getString("state", "");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//if second time
if (intro.equals("done")) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
} else {
//if first time
Intent intent = new Intent(getApplicationContext(), IntroScreenActivity.class);
startActivity(intent);
finish();
}
}
}, 2300);
}
}
将您的 android.support.constraint.ConstraintLayout
更改为 androidx.constraintlayout.widget.ConstraintLayout
我认为您在编写此代码时参考了一些旧文档或教程。
你应该做的第一件事是使用 androidx.constraintlayout.widget.ConstraintLayout
而不是 android.support.constraint.ConstraintLayout
,因为 android.support.constraint.ConstraintLayout
被标记为已弃用(即不应该使用它,它将被删除和以后不可用。)
回到你的问题,这是因为Android无法找到ConstraintLayout的class引起的。由于 ConstraintLayout
不是 Android SDK 的一部分,您需要在应用程序的 build.gradle
文件(位于 app/build.gradle
或 app/build.gradle.kts
) 通过使用以下代码:
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
添加后,只需同步您的项目并重建即可。这将解决您的问题。
此外,您可以在 https://developer.android.com/training/constraint-layout
阅读更多关于约束布局的信息