0
votes

I have a very frustrating error that I cannot explain. I created an Android application that uses Androidx AppCompat to make it compatible with older versions. Here is my main activity layout file: {Androidx}.

here is my java file:

public class SplashScreen extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(SplashScreen.this, MainActivity.class));
            finish();
        }
    }, 1500);
}

here is my xml file:

<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="@drawable/splash_screen"
tools:context=".Activities.SplashScreen">

here is my gradle file

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
    applicationId "com.example.bloodbank"
    minSdkVersion 15
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

} dependencies in gradle file

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

The main problem is my app says that unfortunately app has stopped. here is the details in the run tab

D/skia: --- allocation failed for scaled bitmap D/AndroidRuntime: Shutting down VM E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.bloodbank, PID: 3542 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bloodbank/com.example.bloodbank.Activities.SplashScreen}: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class androidx.constraintlayout.widget.ConstraintLayout at android.view.LayoutInflater.createView(LayoutInflater.java:633) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) at com.example.bloodbank.Activities.SplashScreen.onCreate(SplashScreen.java:16) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:288) at android.view.LayoutInflater.createView(LayoutInflater.java:607) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)  at android.view.LayoutInflater.inflate(LayoutInflater.java:482)  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)  at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)  at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)  at com.example.bloodbank.Activities.SplashScreen.onCreate(SplashScreen.java:16)  at android.app.Activity.performCreate(Activity.java:5990)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  Caused by: java.lang.OutOfMemoryError: Failed to allocate a 711998476 byte allocation with 1048576 free bytes and 383MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988) at android.content.res.Resources.loadDrawableForCookie(Resources.java:2474) at android.content.res.Resources.loadDrawable(Resources.java:2381) at android.content.res.TypedArray.getDrawable(TypedArray.java:749) at android.view.View.(View.java:3737) at android.view.ViewGroup.(ViewGroup.java:497) at android.view.ViewGroup.(ViewGroup.java:493) at android.view.ViewGroup.(ViewGroup.java:489) at androidx.constraintlayout.widget.ConstraintLayout.(ConstraintLayout.java:575) at java.lang.reflect.Constructor.newInstance(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:288)  at android.view.LayoutInflater.createView(LayoutInflater.java:607)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)  at android.view.LayoutInflater.inflate(LayoutInflater.java:482)  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)  at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)  at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)  at com.example.bloodbank.Activities.SplashScreen.onCreate(SplashScreen.java:16)  at android.app.Activity.performCreate(Activity.java:5990)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)  at android.app.ActivityThread.access$800(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:135)  at android.app.ActivityThread.main(ActivityThread.java:5254)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)  Process 3542 terminated.

it shows error in 16th line of splashcreen.java please help me in clearing this error .

Thanks

2
please add gradle file where you are defining constraint layout dependencyWahdat Jan
Your code looks ok though please check if end tag of your androidx.constraintlayout is correct. it should end with />Prashant.J
end tag is closed correctly . there is no syntax kind of errors. build finished correctly but while running app it crashes.(i missed my end tag for that code while posting question. sorry for that )LAKSHMINARAYANAN
i added my gradle file . please make a look at it!LAKSHMINARAYANAN
You might some special character that can't be seen in an editor. Error is straight forward: InflateException: Binary XML file line #2: Error inflating class Anton Novopashin

2 Answers

1
votes

You are actually getting a OutOfMemoryException. It happens when you put a high-resolution image directly in your view. In your case, probably @drawable/splash_screen.

Check out this similar question. An answer is provided for it.

0
votes

I'm not sure if the XML you've pasted is complete or not. If it is, that's an error right there. The Constraint Layout needs a closing tag.