Home > OS >  E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.gameshopservicesdz, PID: 14488
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.gameshopservicesdz, PID: 14488

Time:03-28

  • I am making an app which runs welcome screen ,but when i try to run my app android version like 7.0 or even 7.1 it gives me error on setcontentview(activity_main); !
  • but when i try to run my app android version 11 it start with any problems.

my app original sequence which runs on ver. 11

error for splash screen after welcome if i open splash screen 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);
}

}

CodePudding user response:

I think you have refered to some old documentation or tutorial while writting this code.

The first thing you should do is use androidx.constraintlayout.widget.ConstraintLayout instead of android.support.constraint.ConstraintLayout, since the android.support.constraint.ConstraintLayout is marked as deprecated (i.e. this should not be used and it would be removed and unavailable in future.)

Back to your issue, it is caused since the Android is unable to find the class for ConstraintLayout. Since ConstraintLayout is not a part of Android SDK, you need to add a dependency of ConstraintLayout in your app's build.gradle file (located at app/build.gradle or app/build.gradle.kts) by using following code:

implementation "androidx.constraintlayout:constraintlayout:2.1.3"

After adding this, just sync your project and rebuild. This will resolve you issue.

Also, you can read more about Constraint Layout at https://developer.android.com/training/constraint-layout

CodePudding user response:

Change your android.support.constraint.ConstraintLayout to androidx.constraintlayout.widget.ConstraintLayout

  • Related