gpt4 book ai didi

android - 尝试使用 createNewLayerBuilder() 添加新的 Cyborg Controller 时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 00:23:36 25 4
gpt4 key购买 nike

这就是我在 Application 类中所做的:

@Override
public void onCreate() {
super.onCreate();
CyborgBuilder.startCyborg(new CyborgConfiguration(this, R.layout.cyborgview__auto_reply, BasicModulePack.class));
}

这是 cyborgview__auto_reply.xml 的样子:

<?xml version="1.0" encoding="utf-8"?>
<com.nu.art.cyborg.core.CyborgView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cyborg="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
cyborg:controller="com.hedshafran.autoreply.controllers.Controller_PermissionScreen"
cyborg:tag="Controller_Permission"/>

这就是我在导致崩溃的 Controller_PermissionScreen 类中所做的事情:

createNewLayerBuilder().setControllerType(Controller_MainScreen.class).setLayoutId(R.layout.controller__main_screen).build();

这导致了崩溃,看起来像这样:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hedshafran.autoreply, PID: 17910
java.lang.RuntimeException: Unable to resume activity {com.hedshafran.autoreply/com.nu.art.cyborg.core.CyborgActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.nu.art.cyborg.core.CyborgStackController$StackLayerBuilder com.nu.art.cyborg.core.CyborgStackController.createLayerBuilder()' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3791)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3832)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.nu.art.cyborg.core.CyborgStackController$StackLayerBuilder com.nu.art.cyborg.core.CyborgStackController.createLayerBuilder()' on a null object reference
at com.nu.art.cyborg.core.CyborgController.createNewLayerBuilder(CyborgController.java:506)
at com.hedshafran.autoreply.controllers.Controller_PermissionScreen.onResume(Controller_PermissionScreen.java:35)
at com.nu.art.cyborg.core.CyborgController.dispatchLifeCycleEvent(CyborgController.java:270)
at com.nu.art.cyborg.core.CyborgActivityBridgeImpl.dispatchLifecycleEvent(CyborgActivityBridgeImpl.java:476)
at com.nu.art.cyborg.core.CyborgActivityBridgeImpl.onResume(CyborgActivityBridgeImpl.java:213)
at com.nu.art.cyborg.core.CyborgActivity.onResume(CyborgActivity.java:155)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277)
at android.app.Activity.performResume(Activity.java:7088)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3768)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3832) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6682) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

我怎样才能避免崩溃并以正确的方式打开一个新的 CyborgController?

最佳答案

您的 cyborgview__auto_reply.xml 应该使用将包含您的 Controller_PermissionScreen 的 CyborgStackConroller,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<com.nu.art.cyborg.core.CyborgView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cyborg="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/CV_RootStack"
cyborg:controller="com.nu.art.cyborg.core.CyborgStackController"
cyborg:rootController="com.hedshafran.autoreply.controllers.Controller_PermissionScreen"

cyborg:rootTag="Controller_Permission"
cyborg:tag="RootStack"
/>

要点是,如果调用此方法的 Controller 在堆栈中,则您只能使用 createNewLayerBuilder api。否则使用 getControllerById(R.id.CV_RootStack) 并创建一个新的图层构建器。

关于android - 尝试使用 createNewLayerBuilder() 添加新的 Cyborg Controller 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45824092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com