java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pstiming.mc/com.pstiming.mc.MainActivity}: android.view.InflateException: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
which is copied from the book with the exception of the changed name. Line 10 is the tools:context line which is the same as the book. MainActivity.kt is the same as the book.
That all looks fine to me. Any chance you could post the full stacktrace for the crash? There might be a line with a “Caused by:” message that could really help us narrow down the issue.
FATAL EXCEPTION: main
Process: com.pstiming.mc, PID: 23833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pstiming.mc/com.pstiming.mc.MainActivity}: android.view.InflateException: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3685)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3842)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2252)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.view.InflateException: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: android.view.InflateException: Binary XML file line #10 in com.pstiming.mc:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:858)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1010)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
at android.view.LayoutInflater.inflate(LayoutInflater.java:538)
at android.view.LayoutInflater.inflate(LayoutInflater.java:485)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:461)
at android.app.Activity.setContentView(Activity.java:3523)
at androidx.activity.ComponentActivity.setContentView(ComponentActivity.java:465)
at com.pstiming.mc.MainActivity.onCreate(MainActivity.kt:41)
at android.app.Activity.performCreate(Activity.java:8054)
at android.app.Activity.performCreate(Activity.java:8034)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1341)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3666)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3842)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2252)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.UnsupportedOperationException: FragmentContainerView must be within a FragmentActivity to use android:name="com.pstiming.mc.WaterPoloFragment"
at androidx.fragment.app.FragmentContainerView.<init>(FragmentContainerView.kt:120)
It looks like you might be facing an issue with the XML attributes. Double-check the XML file for any unusual characters or discrepancies in attribute names. In your posted XML snippet, it seems there might be an issue with the double quotes around attributes. Try replacing the curly double quotes (“ ”) with straight double quotes (" ") and see if that resolves the problem. Ensure consistency in attribute naming and spacing. If the issue persists, share more details or the related code for further assistance.
ComponentActivity can also cause a fragment inflation error, as it’s too barebones to support a fragment. If that’s in your activity Java/Kotlin code, then change the activity type to another, such as AppCompatActivity or FragmentActivity.