报错
--------- beginning of system
--------- beginning of main
--------- beginning of crash
2023-12-13 10:16:57.571 32522-32522 e.myapplicatio com.example.myapplication I Late-enabling -Xcheck:jni
2023-12-13 10:16:57.634 32522-32522 e.myapplicatio com.example.myapplication E Unknown bits set in runtime_flags: 0x8000
2023-12-13 10:16:57.635 32522-32522 e.myapplicatio com.example.myapplication W Unexpected CPU variant for X86 using defaults: x86
2023-12-13 10:16:58.024 32522-32555 libEGL com.example.myapplication D Emulator has host GPU support, qemu.gles is set to 1.
2023-12-13 10:16:58.011 32522-32522 RenderThread com.example.myapplication W type=1400 audit(0.0:332): avc: denied { write } for name="property_service" dev="tmpfs" ino=7840 scontext=u:r:untrusted_app:s0:c144,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2023-12-13 10:16:58.025 32522-32555 libc com.example.myapplication W Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2023-12-13 10:16:58.034 32522-32555 libEGL com.example.myapplication D loaded /vendor/lib/egl/libEGL_emulation.so
2023-12-13 10:16:58.035 32522-32555 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2023-12-13 10:16:58.037 32522-32555 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv2_emulation.so
2023-12-13 10:16:58.048 32522-32522 AppCompatDelegate com.example.myapplication D Checking for metadata for AppLocalesMetadataHolderService : Service not found
2023-12-13 10:16:58.113 32522-32522 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2023-12-13 10:16:58.114 32522-32522 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2023-12-13 10:16:58.300 32522-32522 AndroidRuntime com.example.myapplication D Shutting down VM
2023-12-13 10:16:58.302 32522-32522 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 32522
android.view.InflateException: Binary XML file line #353 in com.example.myapplication:layout/fragment_home: ScrollView can host only one direct child
Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.widget.ScrollView.addView(ScrollView.java:379)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at com.example.myapplication.HomeFragment.onCreateView(HomeFragment.java:48)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1425)
at android.app.Activity.performStart(Activity.java:7825)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2023-12-13 10:16:58.311 32522-32522 Process com.example.myapplication I Sending signal. PID: 32522 SIG: 9
2023-12-13 10:19:46.916 371-371 e.myapplicatio com.example.myapplication I Late-enabling -Xcheck:jni
2023-12-13 10:19:46.933 371-371 e.myapplicatio com.example.myapplication E Unknown bits set in runtime_flags: 0x8000
2023-12-13 10:19:46.933 371-371 e.myapplicatio com.example.myapplication W Unexpected CPU variant for X86 using defaults: x86
2023-12-13 10:19:47.199 371-405 libEGL com.example.myapplication D Emulator has host GPU support, qemu.gles is set to 1.
2023-12-13 10:19:47.200 371-405 libc com.example.myapplication W Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2023-12-13 10:19:47.216 371-405 libEGL com.example.myapplication D loaded /vendor/lib/egl/libEGL_emulation.so
2023-12-13 10:19:47.217 371-405 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2023-12-13 10:19:47.221 371-405 libEGL com.example.myapplication D loaded /vendor/lib/egl/libGLESv2_emulation.so
2023-12-13 10:19:47.194 371-371 RenderThread com.example.myapplication W type=1400 audit(0.0:335): avc: denied { write } for name="property_service" dev="tmpfs" ino=7840 scontext=u:r:untrusted_app:s0:c144,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0
2023-12-13 10:19:47.287 371-371 AppCompatDelegate com.example.myapplication D Checking for metadata for AppLocalesMetadataHolderService : Service not found
2023-12-13 10:19:47.362 371-371 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2023-12-13 10:19:47.363 371-371 e.myapplicatio com.example.myapplication W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2023-12-13 10:19:47.543 371-371 AndroidRuntime com.example.myapplication D Shutting down VM
2023-12-13 10:19:47.544 371-371 AndroidRuntime com.example.myapplication E FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 371
android.view.InflateException: Binary XML file line #353 in com.example.myapplication:layout/fragment_home: ScrollView can host only one direct child
Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
at android.widget.ScrollView.addView(ScrollView.java:379)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1127)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1126)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at com.example.myapplication.HomeFragment.onCreateView(HomeFragment.java:48)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:251)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1425)
at android.app.Activity.performStart(Activity.java:7825)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3294)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
2023-12-13 10:19:47.553 371-371 Process com.example.myapplication I Sending signal. PID: 371 SIG: 9
解决
你的错误信息显示了 ScrollView can host only one direct child
的异常。这意味着你的 ScrollView 中包含了多个直接子元素,但 ScrollView 只能有一个直接子元素。你需要确保在 ScrollView 中只放置一个直接的子视图。
在你的布局文件中,你有一个 ScrollView,但它似乎包含了多个直接子元素,这是导致崩溃的原因。你需要将这些直接子元素放到一个单独的容器中,然后将该容器作为 ScrollView 的唯一直接子元素。
要解决这个问题,你可以将你的 LinearLayout
包装在一个新的布局容器中,然后将这个新容器作为 ScrollView 的唯一直接子元素。例如:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- 其他的子视图 -->
</LinearLayout>
</ScrollView>