无法在 Android 的 Tabbar 应用程序中添加 AlertDialog?

发布于 2024-12-25 11:55:13 字数 5798 浏览 3 评论 0原文

我已经为 Android 添加了标签栏,它对于视图来说工作得很好,但是当我尝试使用 AlertDialogs 时,应用程序似乎崩溃了,我添加了日志猫。请就如何解决这个问题向我提供建议。谢谢

01-08 04:14:21.575: E/AndroidRuntime(381): 致命异常:main 01-08 04:14:21.575:E / AndroidRuntime(381):java.lang.RuntimeException:无法启动活动ComponentInfo {com.CarBuyCo / com.CarBuyCo.Tabbed}:java.lang.RuntimeException:无法启动活动ComponentInfo {com.CarBuyCo/com.CarBuyCo.TabGroup1Activity}:java.lang.RuntimeException:无法实例化 Activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Scroller}:java.lang.IllegalStateException:系统服务在 onCreate() 之前不可用于 Activity 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 android.app.ActivityThread.access$1500(ActivityThread.java:117) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.os.Handler.dispatchMessage(Handler.java:99) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.os.Looper.loop(Looper.java:130) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.main(ActivityThread.java:3687) 01-08 04:14:21.575:E / AndroidRuntime(381):在java.lang.reflect.Method.invokeNative(本机方法) 01-08 04:14:21.575:E / AndroidRuntime(381):在java.lang.reflect.Method.invoke(Method.java:507) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 01-08 04:14:21.575:E / AndroidRuntime(381):在dalvik.system.NativeStart.main(本机方法) 01-08 04:14:21.575:E / AndroidRuntime(381):引起:java.lang.RuntimeException:无法启动活动ComponentInfo {com.CarBuyCo / com.CarBuyCo.TabGroup1Activity}:java.lang.RuntimeException:无法启动实例化 Activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Scroller}: java.lang.IllegalStateException:系统服务在 onCreate() 之前不可用于活动 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.startActivityNow(ActivityThread.java:1491) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:657) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.widget.TabHost.setCurrentTab(TabHost.java:329) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.widget.TabHost.addTab(TabHost.java:219) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 com.CarBuyCo.Tabbed.addTab1(Tabbed.java:51) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.Tabbed.setTabs(Tabbed.java:31) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.Tabbed.onCreate(Tabbed.java:23) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 01-08 04:14:21.575: E/AndroidRuntime(381): ... 11 更多 01-08 04:14:21.575:E / AndroidRuntime(381):引起:java.lang.RuntimeException:无法实例化活动ComponentInfo {com.CarBuyCo / com.CarBuyCo.Scroller}:java.lang.IllegalStateException:系统服务onCreate() 之前的活动不可用 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.startActivityNow(ActivityThread.java:1491) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.TabGroupActivity.startChildActivity(TabGroupActivity.java:61) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.TabGroup1Activity.onCreate(TabGroup1Activity.java:10) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 01-08 04:14:21.575: E/AndroidRuntime(381): ... 22 更多 01-08 04:14:21.575:E / AndroidRuntime(381):引起:java.lang.IllegalStateException:onCreate()之前的活动无法使用系统服务 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.Activity.getSystemService(Activity.java:3536) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.android.internal.app.AlertController $AlertParams。(AlertController.java:747) 01-08 04:14:21.575: E/AndroidRuntime(381): 在 android.app.AlertDialog$Builder.(AlertDialog.java:273) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.Scroller.makeAndShowDialogBox(Scroller.java:459) 01-08 04:14:21.575:E / AndroidRuntime(381):在com.CarBuyCo.Scroller。(Scroller.java:33) 01-08 04:14:21.575:E / AndroidRuntime(381):在java.lang.Class.newInstanceImpl(本机方法) 01-08 04:14:21.575:E / AndroidRuntime(381):在java.lang.Class.newInstance(Class.java:1409) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.Instrumentation.newActivity(Instrumentation.java:1021) 01-08 04:14:21.575:E / AndroidRuntime(381):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565) 01-08 04:14:21.575: E/AndroidRuntime(381): ... 29 更多

I have included tabbar for the android its working perfectly for Views but when I try for AlertDialogs the app seems to crash I have added the log cat.Kindly advice me on this on how to resolve this.Thanks

01-08 04:14:21.575: E/AndroidRuntime(381): FATAL EXCEPTION: main
01-08 04:14:21.575: E/AndroidRuntime(381): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Tabbed}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.TabGroup1Activity}: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Scroller}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.os.Looper.loop(Looper.java:130)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-08 04:14:21.575: E/AndroidRuntime(381): at java.lang.reflect.Method.invokeNative(Native Method)
01-08 04:14:21.575: E/AndroidRuntime(381): at java.lang.reflect.Method.invoke(Method.java:507)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
01-08 04:14:21.575: E/AndroidRuntime(381): at dalvik.system.NativeStart.main(Native Method)
01-08 04:14:21.575: E/AndroidRuntime(381): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.TabGroup1Activity}: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Scroller}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:657)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.widget.TabHost.setCurrentTab(TabHost.java:329)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.widget.TabHost.addTab(TabHost.java:219)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.Tabbed.addTab1(Tabbed.java:51)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.Tabbed.setTabs(Tabbed.java:31)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.Tabbed.onCreate(Tabbed.java:23)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-08 04:14:21.575: E/AndroidRuntime(381): ... 11 more
01-08 04:14:21.575: E/AndroidRuntime(381): Caused by: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CarBuyCo/com.CarBuyCo.Scroller}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.TabGroupActivity.startChildActivity(TabGroupActivity.java:61)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.TabGroup1Activity.onCreate(TabGroup1Activity.java:10)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
01-08 04:14:21.575: E/AndroidRuntime(381): ... 22 more
01-08 04:14:21.575: E/AndroidRuntime(381): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.Activity.getSystemService(Activity.java:3536)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.android.internal.app.AlertController$AlertParams.(AlertController.java:747)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.AlertDialog$Builder.(AlertDialog.java:273)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.Scroller.makeAndShowDialogBox(Scroller.java:459)
01-08 04:14:21.575: E/AndroidRuntime(381): at com.CarBuyCo.Scroller.(Scroller.java:33)
01-08 04:14:21.575: E/AndroidRuntime(381): at java.lang.Class.newInstanceImpl(Native Method)
01-08 04:14:21.575: E/AndroidRuntime(381): at java.lang.Class.newInstance(Class.java:1409)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-08 04:14:21.575: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
01-08 04:14:21.575: E/AndroidRuntime(381): ... 29 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜尕妞 2025-01-01 11:55:13

正如日志所示,在调用 Activity 的 oncreate 之前,您无法获取系统服务。
因此,将 getSystemService 调用移至 Oncreate 或之后。

此外,您试图在滚动条本身的构造函数中显示对话框,并且也许您正在将滚动条实例化为字段。将对话框部分移动到其他位置

As the log says you cannot get system service before oncreate of the activity is called.
So move the getSystemService call to Oncreate or after.

Further you are trying to show the dialog box in constructor of scroller itself, and maybe you are instantiating Scroller as a field. Move the dialog box part to somewhere else

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文