From ecdb5b91e194fbde0eee3c3f578019fff3551c81 Mon Sep 17 00:00:00 2001 From: zzz701 Date: Wed, 18 Jun 2025 22:40:28 +0800 Subject: [PATCH] =?UTF-8?q?AsyncCallback=20Error=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E7=9A=84=E5=8F=82=E6=95=B0=20Signed-off-by:?= =?UTF-8?q?=20zzz701=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/entryability/EntryAbility.ets | 4 ++-- code/HelloWorld/entry/src/main/ets/models/MyCallback.ets | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets b/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets index 5158b13b6f..86a9ad622a 100644 --- a/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets @@ -15,10 +15,10 @@ class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { hilog.info(0x0000, 'testTag', 'EntryAbility onWindowStageCreate'); try { - windowStage.loadContent('pages/Index', (err: BusinessError): void => { + windowStage.loadContent('pages/Index', (err: BusinessError | null): void => { hilog.info(0x0000, 'testTag', 'loadContent entering'); MyCallback.runCasesOfCallback(); - if (err.code) { + if (err && err.code) { hilog.info(0x0000, 'testTag', 'loadContent error'); return; } diff --git a/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets b/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets index 5827b846dc..5bdf82c967 100644 --- a/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets +++ b/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets @@ -28,8 +28,10 @@ export class MyCallback { MyCallback.myCallback((data: string) => { hilog.info(0x0000, 'testTag', 'MyCallback' + data); }) - MyCallback.myAsyncCallback((error: BusinessError, result: string) => { - hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}, result:${result}`); + MyCallback.myAsyncCallback((error: BusinessError | null, result: string | undefined) => { + if (error && result) { + hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}, result:${result}`); + } }) MyCallback.myErrorCallback((error: BusinessError) => { hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}`); -- Gitee